Skip to content

Commit

Permalink
add realtime analytics sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ts-3156 committed Mar 26, 2017
1 parent cf38f15 commit 123c69e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions samples/cli/lib/samples/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,23 @@ def show_visits(profile_id)
print_table(data)
end

desc 'show_realtime_visits PROFILE_ID', 'Show realtime visists for the given analytics profile ID'
def show_realtime_visits(profile_id)
analytics = Analytics::AnalyticsService.new
analytics.authorization = user_credentials_for(Analytics::AUTH_ANALYTICS)

dimensions = %w(rt:medium rt:pagePath)
metrics = %w(rt:activeUsers)
sort = %w(rt:medium rt:pagePath)
result = analytics.get_realtime_data("ga:#{profile_id}",
metrics.join(','),
dimensions: dimensions.join(','),
sort: sort.join(','))

data = []
data.push(result.column_headers.map { |h| h.name })
data.push(*result.rows)
print_table(data)
end
end
end

0 comments on commit 123c69e

Please sign in to comment.