"GoogleAnalytics" (Service Connection)
Connect to the Google Analytics API using the Wolfram Language to retrieve and analyze website data.
Connecting & Authenticating
Requests
Report Data of Website Traffic
"ReportData" — retrieve website traffic data
"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" | None | a list of strings to specify dimensions, such as "Hour" or "Day" | |
"Sort" | None | a list of dimensions and metrics indicating the sorting order; using "-" before an element changes the sorting direction | |
"Filters" | None | dimension or metric filters that restrict the data returned for your request | |
"Segment" | None | segments the data returned for your request; accepts an integer Segment ID | |
"SamplingLevel" | "Default" | the desired sampling level out of "Default", "Faster", and "HigherPrecision" | |
"StartIndex" | 1 | start index | |
MaxItems | 1000 | number of elements to return | |
"UserIP" | None | specifies IP address of the end user for whom the API call is being made | |
"QuotaUser" | None | alternative 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
"Metrics" — get a list of available metrics by category
"Dimensions" — get a list of available dimensions by category
"Category" | All | filter by category |
Using ServiceExecute["GoogleAnalytics","Metrics","Categories"] shows all available categories for both "Metrics" and "Dimensions".
All Data
"AllData" — retrieve all information included in the raw output
"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" | None | a list of strings to specify dimensions, such as "Hour" or "Day" | |
"Sort" | None | a list of dimensions and metrics indicating the sorting order; using "-" before an element changes the sorting direction | |
"Filters" | None | dimension or metric filters that restrict the data returned for your request | |
"Fields" | None | reduce the fields included in the output | |
"Segment" | None | segments the data returned for your request; accepts an integer Segment ID | |
"SamplingLevel" | "Default" | the desired sampling level out of "Default", "Faster", and "HigherPrecision" | |
"StartIndex" | 1 | start index | |
MaxItems | 1000 | number of elements to return | |
"UserIP" | None | specifies IP address of the end user for whom the API call is being made | |
"QuotaUser" | None | alternative to "UserIP" in cases when the user's IP address is unknown. |
Parameter Details
"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 |
"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)
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":