"GoogleAnalytics" (Service Connection)

Connect to the Google Analytics API using the Wolfram Language to retrieve and analyze website data.

Connecting & Authenticating

ServiceConnect["GoogleAnalytics"] creates a connection to the Google Analytics API.

Requests

ServiceExecute["GoogleAnalytics","request",params] sends a request to the Google Analytics API, using parameters params. The following give possible requests.

Report Data of Website Traffic

Request:

"ReportData" retrieve website traffic data

Parameters:
  • "ProfileID"(required)the Analytics view (profile) ID associated with the requested data
    "StartDate"(required)requests need a start date; accepts DateObject and strings
    "EndDate"(required)requests need an end date; accepts DateObject and strings
    "Metrics"(required)a list of strings to specify metrics, such as "Sessions" or "Users"
    "Dimensions"Nonea list of strings to specify dimensions, such as "Hour" or "Day"
    "Sort"Nonea list of dimensions and metrics indicating the sorting order; using "-" before an element changes the sorting direction
    "Filters"Nonedimension or metric filters that restrict the data returned for your request
    "Segment"Nonesegments the data returned for your request; accepts an integer Segment ID
    "SamplingLevel""Default"the desired sampling level out of "Default", "Faster", and "HigherPrecision"
    "StartIndex"1start index
    MaxItems1000number of elements to return
    "UserIP"Nonespecifies IP address of the end user for whom the API call is being made
    "QuotaUser"Nonealternative to "UserIP" in cases when the user's IP address is unknown.
  • The "Filters" parameter allows the use of elements in a List to represent the AND operator between them ("Metrics" and "Dimensions" cannot be combined this way). Alternatives is used to represent the OR operator.

    Metrics and Dimensions

    Request:

    "Metrics" get a list of available metrics by category

    "Dimensions" get a list of available dimensions by category

    Parameters:
  • "Category"Allfilter by category
  • Using ServiceExecute["GoogleAnalytics","Metrics","Categories"] shows all available categories for both "Metrics" and "Dimensions".

    All Data

    Request:

    "AllData" retrieve all information included in the raw output

    Parameters:
  • "ProfileID"(required)the Analytics view (profile) ID associated with the requested data
    "StartDate"(required)requests need a start date; accepts DateObject and strings
    "EndDate"(required)requests need an end date; accepts DateObject and strings
    "Metrics"(required)a list of strings to specify metrics, such as "Sessions" or "Users"
    "Dimensions"Nonea list of strings to specify dimensions, such as "Hour" or "Day"
    "Sort"Nonea list of dimensions and metrics indicating the sorting order; using "-" before an element changes the sorting direction
    "Filters"Nonedimension or metric filters that restrict the data returned for your request
    "Fields"Nonereduce the fields included in the output
    "Segment"Nonesegments the data returned for your request; accepts an integer Segment ID
    "SamplingLevel""Default"the desired sampling level out of "Default", "Faster", and "HigherPrecision"
    "StartIndex"1start index
    MaxItems1000number of elements to return
    "UserIP"Nonespecifies IP address of the end user for whom the API call is being made
    "QuotaUser"Nonealternative to "UserIP" in cases when the user's IP address is unknown.
  • Parameter Details

    Possible operators for "Metrics" used with the "Filters" parameter include:
  • "metric""value"equals
    "metric"Except["value"]does not equal
    "metric">"value"greater than
    "metric"<"value"less than
    "metric""value"greater than or equal to
    "metric""value"less than or equal to
  • Possible operators for "Dimensions" used with the "Filters" parameter include:
  • "dimension""value"exact match
    "dimension"Except["value"]does not match
    "dimension""value"contains substring
    "dimension""value"does not contain substring
    "dimension"RegularExpression["value"]contains a match for the regular expression
    "dimension"RegularExpression[Except["value"]]does not match regular expression
  • Examples

    Basic Examples  (4)

    Create a new connection:

    Get dimensions and metrics data for a given "ProfileID":

    Use "ReportData" to get the "Dimensions" and "Metrics" data for a given "ProfileID":

    Use "Sort" to sort by the selected Keys. Sorting direction can be changed using a "-" before the selected keys:

    Filter results by the number of users:

    Filter by multiple constraints; the AND operator is represented by elements in a List:

    The OR operator is represented by Alternatives:

    "AllData" returns all the data associated with the query. The Key "Rows" contains the result of "ReportData":

    Introduced in 2016
     (10.4)