Skip to content

Instantly share code, notes, and snippets.

@jbmyid
Created April 10, 2014 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbmyid/10360132 to your computer and use it in GitHub Desktop.
Save jbmyid/10360132 to your computer and use it in GitHub Desktop.
result = client.execute(:api_method => api_method, :parameters => {
'ids' => "ga:7174565581",
'start-date' => Date.new(1970,1,1).to_s,
'end-date' => Date.today.to_s,
'dimensions' => 'ga:pagePath',
'metrics' => 'ga:pageviews',
'filters' => 'ga:pagePath==/url/to/user'
})
parameters = {
'accountId'=> '~all',
'webPropertyId'=> '~all'
}
flow = Google::APIClient::InstalledAppFlow.new(
:client_id => "811868417598-59bki598nrutjqkd94t36bj8k20g49re.apps.googleusercontent.com",
:client_secret => "fiZmItdLTjHyH6xFwhjp7C3B",
:scope => ['https://www.googleapis.com/auth/analytics.readonly']
)
api_method = client.discovered_api('analytics','v3').data.ga.get
###################################################
client = Google::APIClient.new
client.authorization.client_id = "811868417598-59bki598nrutjqkd94t36bj8k20g49re.apps.googleusercontent.com"
client.authorization.client_secret = "fiZmItdLTjHyH6xFwhjp7C3B"
client.authorization.scope = 'https://www.googleapis.com/auth/analytics.readonly'
client.authorization.token_credential_uri = "https://accounts.google.com/o/oauth2/token"
api_method = client.discovered_api('analytics','v3')
## result = client.execute(:api_method => analytics.management.profiles.list, parameters: parameters, authorization: client.authorization)
analytics = client.discovered_api('analytics', 'v3')
parameters = {
'accountId': '~all',
'webPropertyId': '~all'
}
result = client.execute(:api_method => analytics.management.profiles.list, parameters: parameters)
profiles = result.data.items
parameters = {
'ids' => "ga:#{profiles.first.id}",
'start-date' => (Date.today - 30).strftime("%Y-%m-%d"),
'end-date' => Date.today.strftime("%Y-%m-%d"),
'metrics' => "ga:avgTimeOnPage",
'filters' => "ga:pagePath=~/"
}
result = client.execute(:api_method => analytics.data.ga.get, :parameters => parameters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment