# PageSpeed Insights API . pagespeedapi

## Instance Methods

Runs PageSpeed analysis on the page at the specified URL, and returns PageSpeed scores, a list of suggestions to make that page faster, and other information.

### Method Details

`runpagespeed(url, utm_campaign=None, screenshot=None, locale=None, rule=None, snapshots=None, strategy=None, filter_third_party_resources=None, utm_source=None)`

    Runs PageSpeed analysis on the page at the specified URL, and returns PageSpeed scores, a list of suggestions to make that page faster, and other information.

    Args:
      url: string, The URL to fetch and analyze (required)
      utm_campaign: string, Campaign name for analytics.
      screenshot: boolean, Indicates if binary data containing a screenshot should be included
      locale: string, The locale used to localize formatted results
      rule: string, A PageSpeed rule to run; if none are given, all rules are run (repeated)
      snapshots: boolean, Indicates if binary data containing snapshot images should be included
      strategy: string, The analysis strategy (desktop or mobile) to use, and desktop is the default
        Allowed values
          desktop - Fetch and analyze the URL for desktop browsers
          mobile - Fetch and analyze the URL for mobile devices
      filter_third_party_resources: boolean, Indicates if third party resources should be filtered out before PageSpeed analysis.
      utm_source: string, Campaign source for analytics.

    Returns:
      An object of the form:

        {
        "kind": "pagespeedonline#result", # Kind of result.
        "captchaResult": "A String", # The captcha verify result
        "responseCode": 42, # Response code for the document. 200 indicates a normal page load. 4xx/5xx indicates an error.
        "screenshot": { # Base64-encoded screenshot of the page that was analyzed.
          "height": 42, # Height of screenshot in pixels.
          "width": 42, # Width of screenshot in pixels.
          "key": "A String", # Unique string key, if any, identifying this image.
          "page_rect": {
            "width": 42,
            "top": 42,
            "left": 42,
            "height": 42,
          },
          "data": "A String", # Image data base64 encoded.
          "mime_type": "A String", # Mime type of image data (e.g. "image/jpeg").
        },
        "title": "A String", # Title of the page, as displayed in the browser's title bar.
        "ruleGroups": { # A map with one entry for each rule group in these results.
          "a_key": { # The name of this rule group: one of "SPEED", "USABILITY", or "SECURITY".
            "score": 42, # The score (0-100) for this rule group, which indicates how much better a page could be in that category (e.g. how much faster, or how much more usable, or how much more secure). A high score indicates little room for improvement, while a lower score indicates more room for improvement.
            "pass": True or False,
          },
        },
        "snapshots": [ # Additional base64-encoded screenshots of the page, in various partial render states.
          {
            "height": 42, # Height of screenshot in pixels.
            "width": 42, # Width of screenshot in pixels.
            "key": "A String", # Unique string key, if any, identifying this image.
            "page_rect": {
              "width": 42,
              "top": 42,
              "left": 42,
              "height": 42,
            },
            "data": "A String", # Image data base64 encoded.
            "mime_type": "A String", # Mime type of image data (e.g. "image/jpeg").
          },
        ],
        "loadingExperience": { # Metrics of end users' page loading experience.
          "metrics": {
            "a_key": { # The type of the metric.
              "category": "A String",
              "median": 42,
              "distributions": [
                {
                  "max": 42,
                  "proportion": 3.14,
                  "min": 42,
                },
              ],
            },
          },
          "id": "A String", # The url, pattern or origin which the metrics are on.
          "overall_category": "A String",
          "initial_url": "A String",
        },
        "version": { # The version of PageSpeed used to generate these results.
          "major": 42, # The major version number of PageSpeed used to generate these results.
          "minor": 42, # The minor version number of PageSpeed used to generate these results.
        },
        "formattedResults": { # Localized PageSpeed results. Contains a ruleResults entry for each PageSpeed rule instantiated and run by the server.
          "locale": "A String", # The locale of the formattedResults, e.g. "en_US".
          "ruleResults": { # Dictionary of formatted rule results, with one entry for each PageSpeed rule instantiated and run by the server.
            "a_key": { # The enum-like identifier for this rule. For instance "EnableKeepAlive" or "AvoidCssImport". Not localized.
              "ruleImpact": 3.14, # The impact (unbounded floating point value) that implementing the suggestions for this rule would have on making the page faster. Impact is comparable between rules to determine which rule's suggestions would have a higher or lower impact on making a page faster. For instance, if enabling compression would save 1MB, while optimizing images would save 500kB, the enable compression rule would have 2x the impact of the image optimization rule, all other things being equal.
              "summary": { # A brief summary description for the rule, indicating at a high level what should be done to follow the rule and what benefit can be gained by doing so.
                "args": [ # List of arguments for the format string.
                  {
                    "rects": [ # The screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments. If this is absent for a SNAPSHOT_RECT argument, it means that that argument refers to the entire snapshot.
                      {
                        "width": 42,
                        "top": 42,
                        "left": 42,
                        "height": 42,
                      },
                    ],
                    "value": "A String", # Argument value, as a localized string.
                    "type": "A String", # Type of argument. One of URL, STRING_LITERAL, INT_LITERAL, BYTES, DURATION, VERBATIM_STRING, PERCENTAGE, HYPERLINK, or SNAPSHOT_RECT.
                    "secondary_rects": [ # Secondary screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments.
                      {
                        "width": 42,
                        "top": 42,
                        "left": 42,
                        "height": 42,
                      },
                    ],
                    "key": "A String", # The placeholder key for this arg, as a string.
                  },
                ],
                "format": "A String", # A localized format string with {{FOO}} placeholders, where 'FOO' is the key of the argument whose value should be substituted. For HYPERLINK arguments, the format string will instead contain {{BEGIN_FOO}} and {{END_FOO}} for the argument with key 'FOO'.
              },
              "beta": True or False, # Whether this rule is in 'beta'. Rules in beta are new rules that are being tested, which do not impact the overall score.
              "groups": [ # List of rule groups that this rule belongs to. Each entry in the list is one of "SPEED", "USABILITY", or "SECURITY".
                "A String",
              ],
              "localizedRuleName": "A String", # Localized name of the rule, intended for presentation to a user.
              "urlBlocks": [ # List of blocks of URLs. Each block may contain a heading and a list of URLs. Each URL may optionally include additional details.
                {
                  "header": { # Heading to be displayed with the list of URLs.
                    "args": [ # List of arguments for the format string.
                      {
                        "rects": [ # The screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments. If this is absent for a SNAPSHOT_RECT argument, it means that that argument refers to the entire snapshot.
                          {
                            "width": 42,
                            "top": 42,
                            "left": 42,
                            "height": 42,
                          },
                        ],
                        "value": "A String", # Argument value, as a localized string.
                        "type": "A String", # Type of argument. One of URL, STRING_LITERAL, INT_LITERAL, BYTES, DURATION, VERBATIM_STRING, PERCENTAGE, HYPERLINK, or SNAPSHOT_RECT.
                        "secondary_rects": [ # Secondary screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments.
                          {
                            "width": 42,
                            "top": 42,
                            "left": 42,
                            "height": 42,
                          },
                        ],
                        "key": "A String", # The placeholder key for this arg, as a string.
                      },
                    ],
                    "format": "A String", # A localized format string with {{FOO}} placeholders, where 'FOO' is the key of the argument whose value should be substituted. For HYPERLINK arguments, the format string will instead contain {{BEGIN_FOO}} and {{END_FOO}} for the argument with key 'FOO'.
                  },
                  "urls": [ # List of entries that provide information about URLs in the url block. Optional.
                    {
                      "details": [ # List of entries that provide additional details about a single URL. Optional.
                        {
                          "args": [ # List of arguments for the format string.
                            {
                              "rects": [ # The screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments. If this is absent for a SNAPSHOT_RECT argument, it means that that argument refers to the entire snapshot.
                                {
                                  "width": 42,
                                  "top": 42,
                                  "left": 42,
                                  "height": 42,
                                },
                              ],
                              "value": "A String", # Argument value, as a localized string.
                              "type": "A String", # Type of argument. One of URL, STRING_LITERAL, INT_LITERAL, BYTES, DURATION, VERBATIM_STRING, PERCENTAGE, HYPERLINK, or SNAPSHOT_RECT.
                              "secondary_rects": [ # Secondary screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments.
                                {
                                  "width": 42,
                                  "top": 42,
                                  "left": 42,
                                  "height": 42,
                                },
                              ],
                              "key": "A String", # The placeholder key for this arg, as a string.
                            },
                          ],
                          "format": "A String", # A localized format string with {{FOO}} placeholders, where 'FOO' is the key of the argument whose value should be substituted. For HYPERLINK arguments, the format string will instead contain {{BEGIN_FOO}} and {{END_FOO}} for the argument with key 'FOO'.
                        },
                      ],
                      "result": { # A format string that gives information about the URL, and a list of arguments for that format string.
                        "args": [ # List of arguments for the format string.
                          {
                            "rects": [ # The screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments. If this is absent for a SNAPSHOT_RECT argument, it means that that argument refers to the entire snapshot.
                              {
                                "width": 42,
                                "top": 42,
                                "left": 42,
                                "height": 42,
                              },
                            ],
                            "value": "A String", # Argument value, as a localized string.
                            "type": "A String", # Type of argument. One of URL, STRING_LITERAL, INT_LITERAL, BYTES, DURATION, VERBATIM_STRING, PERCENTAGE, HYPERLINK, or SNAPSHOT_RECT.
                            "secondary_rects": [ # Secondary screen rectangles being referred to, with dimensions measured in CSS pixels. This is only ever used for SNAPSHOT_RECT arguments.
                              {
                                "width": 42,
                                "top": 42,
                                "left": 42,
                                "height": 42,
                              },
                            ],
                            "key": "A String", # The placeholder key for this arg, as a string.
                          },
                        ],
                        "format": "A String", # A localized format string with {{FOO}} placeholders, where 'FOO' is the key of the argument whose value should be substituted. For HYPERLINK arguments, the format string will instead contain {{BEGIN_FOO}} and {{END_FOO}} for the argument with key 'FOO'.
                      },
                    },
                  ],
                },
              ],
            },
          },
        },
        "invalidRules": [ # List of rules that were specified in the request, but which the server did not know how to instantiate.
          "A String",
        ],
        "pageStats": { # Summary statistics for the page, such as number of JavaScript bytes, number of HTML bytes, etc.
          "overTheWireResponseBytes": "A String", # Number of over-the-wire bytes, uses the default gzip compression strategy as an estimation.
          "numberTransientFetchFailureResources": 42, # Number of transient-failed resources.
          "otherResponseBytes": "A String", # Number of response bytes for other resources on the page.
          "flashResponseBytes": "A String", # Number of response bytes for flash resources on the page.
          "numberResources": 42, # Number of HTTP resources loaded by the page.
          "numTotalRoundTrips": 42, # The needed round trips to load the full page
          "numberCssResources": 42, # Number of CSS resources referenced by the page.
          "numRenderBlockingRoundTrips": 42, # The needed round trips to load render blocking resources
          "totalRequestBytes": "A String", # Total size of all request bytes sent by the page.
          "numberJsResources": 42, # Number of JavaScript resources referenced by the page.
          "cssResponseBytes": "A String", # Number of uncompressed response bytes for CSS resources on the page.
          "javascriptResponseBytes": "A String", # Number of uncompressed response bytes for JS resources on the page.
          "imageResponseBytes": "A String", # Number of response bytes for image resources on the page.
          "robotedUrls": [ # List of roboted urls.
            "A String",
          ],
          "numberHosts": 42, # Number of unique hosts referenced by the page.
          "numberStaticResources": 42, # Number of static (i.e. cacheable) resources on the page.
          "htmlResponseBytes": "A String", # Number of uncompressed response bytes for the main HTML document and all iframes on the page.
          "numberRobotedResources": 42, # Number of roboted resources.
          "transientFetchFailureUrls": [ # List of transient fetch failure urls.
            "A String",
          ],
          "cms": "A String", # Content management system (CMS) used for the page.
          "textResponseBytes": "A String", # Number of uncompressed response bytes for text resources not covered by other statistics (i.e non-HTML, non-script, non-CSS resources) on the page.
        },
        "id": "A String", # Canonicalized and final URL for the document, after following page redirects (if any).
      }