Skip to content

bithauschile/datadog-ga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

datadog-ga

Datadog custom check for collecting Google Analytics Real Time data.

This custom check allows you to retrieve Google Analytics information from the Real Time API and send it as a regular metric to Datadog.

  • Support for multiple profiles (views)
  • Handles Active users (rt:activeUsers) and Pageviews (rt:pageviews) metrics
  • Allows for custom tagging for each profile
  • Allows for dimension-tag mapping for pageviews metric. Example: adding rt:country dimension, generate the #country: tag.

Installation

In order for the integration to work you must create a Service Account, obtain it's API key and give permission to access Analytics API by adding the Service Account e-mail to the Authorised users in that Property. If you are ready with this, go directly to Step 3: Installing the check.

Step 1 : Get a service account and API key

  1. Create a project
  2. Go to https://console.developers.google.com
  3. Upper right > Select a project
  4. Create a project or select an existing one
  5. Enable Google Analytics API
  6. In the left menu "API Manager", go to Overview
  7. In the search box type "analytics"
  8. Click on Analytics API
  9. Enable
  10. Create Access Credentials
  11. In the left menu "API Manager", go to Credentials
  12. Create credential > Service Account keys
  13. Select "New service account" and type in the name of it
  14. Select json for key file
  15. When done, don't forget to save the key json file
  16. Take note of service account email (ie: my-svc-account@my-project.12345.iam.gserviceaccount.com)

Step 2 : Authorize service account to query analytics

  1. Go into https://analytics.google.com and log in
  2. Go to Admin option in header menu
  3. Select the account you want to integrate. You may also select the specific property you want to give access.
  4. Goto to User Management
  5. Add permissions for the service account email address (Read & Analyze)
  6. Select the property and the view you wish to collect metrics from
  7. Take note of the View ID for later (ie: 12345678)

Step 3: Install the check (Finally!)

This steps are based on Ubuntu Linux.

  1. Clone or download from https://github.com/bithauschile/datadog-ga
  2. Install python libraries
  3. Use pip to install the Google API client for Python: /opt/datadog-agent/embedded/bin/pip install --upgrade google-api-python-client
  4. Install the check:
  • Copy ga.yaml to /etc/datadog-agent/conf.d/
  • Copy ga.py to /etc/datadog-agent/checks.d/
  • Copy the api key json file to the server in a directory the agent can access (ie: /etc/datadog-agent/conf.d/)
  1. Configure by adding the account information and the properties (views) you want to integrate in /etc/datadog-agent/conf.d/ga.yaml.
  • In the following example, the query divides the pageviews in 3 dimensions (country, city, device). For more information about available dimensions go to this page.
  • Be carefull with the min_collection_interval paramter. Google Analytics generate a by-minute result in the Real Time response with no timestamp. The only way to correlate Analytics data with the other metrics is running every 60 seconds aprox.
  init_config:
    min_collection_interval: 55
    service_account_email: my-svc-account@my-project.12345.iam.gserviceaccount.com
    key_file_location: /etc/datadog-agent/conf.d/key.json

  instances:

    - profile: ga:123456789
      tags:
       - env:test
      pageview_dimensions:
       - rt:country
       - rt:city
       - rt:deviceCategory 

Done!

Check that everything went right: /etc/init.d/datadog-agent check ga.

  • Restart the agent: /etc/init.d/datadog-agent restart.

##References

##Licence The code is licensed under the MIT License.

About

Datadog custom check for Google Analytics Real Time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages