Google Analytics

Has anyone gone and brought Google Analytics data in via the API into Squared Up?

3 Likes

We’re using the WebAPI tile to achieve this. To set it up just follow the below steps:

  1. Obtain a Client ID & Secret from the Google Developer Console
    1. Visit https://console.developers.google.com/apis/credentials
    2. Create a new project as required
    3. Select Create Credentials -> OAuth Client ID
    4. Select Web Application
    5. Enter the following:
      1. Name: can be anything
      2. Authorised JavaScript origins: Should be the hostname including http/https of your Squared Up server
      3. Authorised Redirect URIs: Should be the URL to your Squared Up installation followed by /ext-core-webapi/callback/google, for example: https://mysquaredup/SquaredUpv3/ext-core-webapi/callback/google
    6. Click save/create
    7. Note down the Client ID & Secret, you’ll need these later.
  2. In Squared Up, add a new provider via the system -> web api menu using these details:

Provider Type: oauth Grant Type: authorization code (default) Base URL: https://www.googleapis.com/ Ignore Invalid SSL: off (default) Authorization URL: https://accounts.google.com/o/oauth2/v2/auth Token URL: https://www.googleapis.com/oauth2/v4/token Client ID: From above Client Secret: From above Authorization Scope: https://www.googleapis.com/auth/analytics.readonly

  1. Click save, then click perform authorization (you’ll be redirect to Google to login & authorize and then back to Squared Up).
  2. The provider should now display a green tick.
  3. Now the provider is ready, you can now create a dashboard – here’s an example display pageviews.
  4. Create a new dashboard (+)
  5. Select the WEB API -> Scalar tile
  6. Select your new provider, as above.
  7. Enter the following URL: /analytics/v3/data/ga?ids=ga%3A5###ACCOUNTID###&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Apageviews
    1. Generate this URL with your account ID using the Google Query Explorer (https://ga-dev-tools.appspot.com/query-explorer/)
      1. Select your Account, Property, and View
      2. Under metrics, start typing pageviews and select Page Views (ga:pageviews)
      3. Click Run Query
      4. Grab the URL (minus the https://www.googleapis.com/) from the API Query URI section
  8. Hit next twice
  9. Under response data, enter: rows.0.0
  10. Under scalar, enter the unit: pageviews
  11. Hit done, et voila!

To retrieve different metrics or tabular data, use the Google Query Explorer (Query Explorer — Google Analytics Demos & Tools) to generate the API query url and then swap that out in step 7 above.

5 Likes

Clark/Vyper,

We have been able to get the provider to work in Squared Up. Now we are experiencing that if you leave the session of Squared Up, the provider will require to have the perform authorization. Once this is done, all is ok. My question, could it be that there is no activity yet? Have yes to pull anything. Will work on building some pages. Also, once I get this finalized I will share the solution that we employed so the connection could be achieved.

1 Like

Clark,

How did you get past the need for the public top level domain for the authorized redirect URLs? My server is not on the public internet, which does not allow it to have a public top level domain. Is this something that I need to do in order for this to work?

Mike

Hi michouser, you should just be able to use the FQDN of your server - although mine happens to end in .net so that might be why it works. It doesn’t need to be on the public internet. You only need the redirect URI to be valid for initial authorisation, so you could modify your hosts file to temporarily map michouser.com (for example) to your servers local IP and use that as the authorised redirect URI. Does that make sense?

Also worth noting, the name you choose for the provider will be what is on the end of the Authorised Redirect URL in step 1.5.3. So in the example above clarkd called his provider google hence why his redirect url ended in /ext-core-webapi/callback/google.

Hi michouser, did you get it working in the end?

The one thing that I am expericing now is that after a period of time the API connection becomes unauthorized. When this occurs, I have to go to settings and reauthorize. Is there a work around so this does not occur?