Skip to content

jensbits/CF-GA-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CF-GA-service

Accessing Google Analytics API with Service Account and Coldfusion

See http://www.jensbits.com/2013/12/28/google-analytics-api-offline-access-with-service-account-and-coldfusion/

For the Google Analytics Real Time API with Servie Account and Coldfusion

See http://www.jensbits.com/2014/07/31/google-analytics-real-time-api-access-with-service-account-and-coldfusion/

Set up credentials for accessing GA as service:

  1. Create your project in the Google console: https://code.google.com/apis/console

  2. Go to API's & Auth and turn off all but the Analytics API.

  3. Go to Credentials (under API's) and click Create a New Client ID.

  4. Select Service Account from the pop up.

  5. Save the .p12 file it will prompt you to download to a non-browsable place on your webserver. Feel free to rename it but keep the .p12 extension.

  6. The service account email address will be under the Service Account setting box as Email Address and be in the form of xxxxxxxxxxxxxx@developer.gserviceaccount.com (the really long email). Add this email to the Google analytics profile(s) as a user with Read & Analyze access.

Add the .jar files to the CF server

  1. Add the Google Analytics API v3 client library .jar files to the CF server in the WEB-INF/lib folder. The files can be currently found at: https://developers.google.com/api-client-library/java/apis/analytics/v3 The readme.html will list the dependencies. As of April 2015 they are the following when using Jackson 2:
  • google-api-services-analytics-v3-rev115-1.20.0.jar
  • google-api-client-1.20.0.jar
  • google-oauth-client-1.20.0.jar
  • google-http-client-1.20.0.jar
  • jsr305-1.3.9.jar
  • google-http-client-jackson2-1.20.0.jar
  • jackson-core-2.1.3.jar
  1. Restart the CF server (if you installed the .jar files directly on the server).

Save the cfanalytics.cfc to your web root

  1. Save the cfanalytics folder to your web root or where you keep your com objects.

  2. init() the cfanalytics object. This can be done as an application variable. The pathToKeyFile = expandPath("/your-path-to-key-file/your-key-name.p12"). Make sure this is non-browsable!

  3. Call the getProfile() method to get the profile ID for the tableId parameter in the getData() and getRealTimeData() method.

  4. Call the getData() method to access data or the getRealTimeData() method for real time data.

  5. Use the following links for references on getting profile information and data from GA:

For the Core Reporting API:

For the Real Time API