Title: | Unsampled Data in R for Google Analytics Premium Accounts |
---|---|
Description: | It fires a query to the API to get the unsampled data in R for Google Analytics Premium Accounts. It retrieves data from the Google drive document and stores it into the local drive. The path to the excel file is returned by this package. The user can read data from the excel file into R using read.csv() function. |
Authors: | Jalpa Joshi Dave |
Maintainer: | Jalpa Joshi Dave <[email protected]> |
License: | Apache License 2.0 |
Version: | 0.1.1 |
Built: | 2025-01-20 03:55:12 UTC |
Source: | https://github.com/cran/RGoogleAnalyticsPremium |
This function expects a Client ID and Client Secret. In order to obtain these, you will have to register an application with the Google Analytics API. This can be done as follows
- Go to https://console.developers.google.com
- Create a New Project and enable the Google Analytics API, Contacts API and Drive API
- On the Credentials screen, create a new Client ID for Application Type "Installed Application".
- Copy the Client ID and Client Secret to your R Script as shown in the Examples section below
Auth(client.id, client.secret)
Auth(client.id, client.secret)
client.id |
Equivalent to a user name |
client.secret |
Equivalent to a password |
When evaluated for the first time this function asks for User Consent
for the Google Analytics Account and creates a OAuth Token Object.
The token object can be saved locally to a file on the user's system.
In subsequent runs, User Consent is not required unless you are querying a
Google Analytics profile associated with a different email account.
This function uses oauth2.0_token
under the hood to
create the OAuth Tokens. The Access Token has a 60 minute lifetime after
which it expires and a new token has to be obtained. This can be done using
the ValidateToken
method
google.token A Token object containing all the data required for
OAuth access. See Token2.0
for additional information
on the Token object
## Not run: # Generate the oauth_token object oauth_token <- Auth(client.id = "150487456763-XXXXXXXXXXXXXXX.apps.googleusercontent.com", client.secret = "TUXXXXXXXXXXXX_TknUI") # Save the token object for future sessions save(oauth_token, file="oauth_token") # Load the token object load("oauth_token") ## End(Not run)
## Not run: # Generate the oauth_token object oauth_token <- Auth(client.id = "150487456763-XXXXXXXXXXXXXXX.apps.googleusercontent.com", client.secret = "TUXXXXXXXXXXXX_TknUI") # Save the token object for future sessions save(oauth_token, file="oauth_token") # Load the token object load("oauth_token") ## End(Not run)
Query the Google Analytics Premium API for the specified dimensions, metrics and other query parameters
GetFile(query.builder, token, accountid, webpropertyid, profileid)
GetFile(query.builder, token, accountid, webpropertyid, profileid)
query.builder |
Name of the object created using |
token |
Name of the token object created using |
accountid |
Google analytics premium account id |
webpropertyid |
Webproperty ID for google analytics premium account |
profileid |
View ID for google analytics premium account |
It returns path to file on local drive that contains extracted unsampled data.
This function takes all the query parameters and combines them into a single
list that is to be passed as an argument to QueryBuilder
. Note
that parameter validation is performed when the QueryBuilder
object is created
Init(end.date = NULL, metrics = NULL, start.date = NULL, title = NULL, dimensions = NULL, filters = NULL, segments = NULL)
Init(end.date = NULL, metrics = NULL, start.date = NULL, title = NULL, dimensions = NULL, filters = NULL, segments = NULL)
end.date |
End Date for fetching Analytics Data. End Date must be of the format "%Y-%m-%d" |
metrics |
A vector of up to 10 metrics, either as a single string or a vector or strings. E.g. "ga:sessions" or c("ga:sessions", "ga:bounces"). |
start.date |
Start Date for fetching Analytics Data. Start Date must be of the format "%Y-%m-%d" |
title |
Title of unsampled report. |
dimensions |
Optional. A vector of up to 4 dimensions, either as a single string or a vector or strings, E.g. "ga:source,ga:medium" or c("ga:source", "ga:medium"). |
filters |
Optional.The filter string for the GA request.e.g. "ga:medium==referral". |
segments |
Optional.An advanced segment definition to slice and dice your Analytics data. |
List of all the Query Parameters initialized by the user
Initialize a QueryBuilder object with the given parameters and perform validation
QueryBuilder(query.params.list)
QueryBuilder(query.params.list)
query.params.list |
List of all the Query Parameters. See |
The builder object to process the query parameters.
Returns the URI constructed from the parameter settings. This also URI-encodes all the values in each query parameter.
ToBody(query.builder, token)
ToBody(query.builder, token)
query.builder |
Name of the Object of the Query Builder Class |
token |
Token object containing the OAuth2.0 Authentication details |
A full URI that can be used with the Google Analytics API.
This function checks whether the Access Token is expired. If yes, it generates a new Access Token and updates the token object.
ValidateToken(token)
ValidateToken(token)
token |
Token object containing the OAuth authentication parameters |