"GoogleAnalytics" (Service Connection)
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)
googleAnalytics = ServiceConnect["GoogleAnalytics"]Get dimensions and metrics data for a given "ProfileID":
googleAnalytics["ReportData", {"ProfileID" -> 81052926,
"Dimensions" -> "Date",
"Metrics" -> "Sessions",
"StartDate" -> "August 29, 2015", "EndDate" -> "September 28, 2015",
MaxItems -> 1000, "StartIndex" -> 1, "SamplingLevel" -> "HigherPrecision"}]Use "ReportData" to get the "Dimensions" and "Metrics" data for a given "ProfileID":
googleAnalytics["ReportData", {"ProfileID" -> 31920685,
"Dimensions" -> "Language",
"Metrics" -> {"Sessions", "Users", "BounceRate", "AvgSessionDuration"},
"Sort" -> {"-Sessions"},
"StartDate" -> DateObject[{2014, 7, 1}], "EndDate" -> "August 2014",
MaxItems -> 16, "StartIndex" -> 1, "SamplingLevel" -> "HigherPrecision"}]Use "Sort" to sort by the selected Keys. Sorting direction can be changed using a "-" before the selected keys:
googleAnalytics["ReportData", {"ProfileID" -> 81052926,
"Dimensions" -> "Language",
"Metrics" -> {"Sessions", "NewUsers"},
"Sort" -> "-Sessions",
"StartDate" -> "August 29, 2015", "EndDate" -> "September 28, 2015",
MaxItems -> 100, "StartIndex" -> 1}]Filter results by the number of users:
googleAnalytics["ReportData", {"ProfileID" -> 31920685,
"Dimensions" -> {"Day", "Hour"},
"Metrics" -> "Users",
"Sort" -> "-Users",
"StartDate" -> DateObject[{2014, 7, 1}], "EndDate" -> DateObject[{2014, 8, 1}],
MaxItems -> 16, "StartIndex" -> 1,
"Filters" -> "Users" > 18500}]Filter by multiple constraints; the AND operator is represented by elements in a List:
googleAnalytics["ReportData", {"ProfileID" -> 31920685,
"Dimensions" -> {"Day", "Hour"},
"Metrics" -> "Users",
"Sort" -> "-Users",
"StartDate" -> DateObject[{2014, 7, 1}], "EndDate" -> DateObject[{2014, 8, 1}],
MaxItems -> 16, "StartIndex" -> 1,
"Filters" -> {"Users" > 18500, "Hour" -> "10"}}]The OR operator is represented by Alternatives:
googleAnalytics["ReportData", {"ProfileID" -> 31920685,
"Dimensions" -> {"OperatingSystem", "Browser"},
"Metrics" -> "Hits",
"Sort" -> {"-Hits", "-Browser", "OperatingSystem"},
"StartDate" -> DateObject[{2014, 7, 1}], "EndDate" -> DateObject[{2014, 8, 1}],
MaxItems -> 16, "StartIndex" -> 1, "Filters" -> {("OperatingSystem" -> "Windows") | ("OperatingSystem" -> "Macintosh"), ("Browser" -> "Firefox") | ("Browser" -> "Chrome")}}]"AllData" returns all the data associated with the query. The Key "Rows" contains the result of "ReportData":
googleAnalytics["AllData", {"ProfileID" -> 31920685,
"Dimensions" -> {"Day", "Hour"}, "Metrics" -> { "Users", "Sessions"},
"StartDate" -> DateObject[{2014, 7, 1}], "EndDate" -> DateObject[{2014, 8, 1}], MaxItems -> 16, "StartIndex" -> 1}]