# Google Analytics

**URL:** <https://community.squaredup.com/t/google-analytics/562>\
**Category:** Dashboard Server\
**Tags:** api, google, google-analytics\
**Created:** [December 5, 2017, 8:19pm UTC](https://community.squaredup.com/t/google-analytics/562 "2017-12-05T20:19:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![michouser](https://community.squaredup.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@michouser](https://community.squaredup.com/u/michouser)\
**Post date:** [December 5, 2017, 8:19pm UTC](https://community.squaredup.com/t/google-analytics/562/1 "2017-12-05T20:19:18Z")

</div>

Has anyone gone and brought _Google Analytics_ data in via the API into Squared Up?

---

<div class="post-metadata">

**Author:** ![clarkd](https://community.squaredup.com/user_avatar/community.squaredup.com/clarkd/32/764_2.png) [@clarkd](https://community.squaredup.com/u/clarkd)\
**Post date:** [December 6, 2017, 10:19am UTC](https://community.squaredup.com/t/google-analytics/562/2 "2017-12-06T10:19:02Z")

</div>

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](https://console.developers.google.com/apis/credentials)
  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!

 ![pageviews.png](https://community-cdn.squaredup.com/original/1X/623d9e968ffb71b0164f9f74dca76e0ea4474185.png)

To retrieve different metrics or tabular data, use the [Google Query Explorer](https://ga-dev-tools.appspot.com/query-explorer/)([Query Explorer — Google Analytics Demos & Tools](https://ga-dev-tools.appspot.com/query-explorer/)) to generate the API query url and then swap that out in step 7 above.

---

<div class="post-metadata">

**Author:** ![michouser](https://community.squaredup.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@michouser](https://community.squaredup.com/u/michouser)\
**Post date:** [December 14, 2017, 7:57pm UTC](https://community.squaredup.com/t/google-analytics/562/3 "2017-12-14T19:57:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![michouser](https://community.squaredup.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@michouser](https://community.squaredup.com/u/michouser)\
**Post date:** [December 6, 2017, 4:12pm UTC](https://community.squaredup.com/t/google-analytics/562/4 "2017-12-06T16:12:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![clarkd](https://community.squaredup.com/user_avatar/community.squaredup.com/clarkd/32/764_2.png) [@clarkd](https://community.squaredup.com/u/clarkd)\
**Post date:** [December 6, 2017, 4:21pm UTC](https://community.squaredup.com/t/google-analytics/562/5 "2017-12-06T16:21:23Z")

</div>

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](http://michouser.com) (for example) to your servers local IP and use that as the authorised redirect URI. Does that make sense?

---

<div class="post-metadata">

**Author:** ![viper](https://community.squaredup.com/user_avatar/community.squaredup.com/viper/32/769_2.png) [@viper](https://community.squaredup.com/u/viper)\
**Post date:** [December 12, 2017, 12:35pm UTC](https://community.squaredup.com/t/google-analytics/562/6 "2017-12-12T12:35:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![clarkd](https://community.squaredup.com/user_avatar/community.squaredup.com/clarkd/32/764_2.png) [@clarkd](https://community.squaredup.com/u/clarkd)\
**Post date:** [December 12, 2017, 12:38pm UTC](https://community.squaredup.com/t/google-analytics/562/7 "2017-12-12T12:38:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![michouser](https://community.squaredup.com/letter_avatar_proxy/v4/letter/m/3ec8ea/32.png) [@michouser](https://community.squaredup.com/u/michouser)\
**Post date:** [February 22, 2018, 3:10pm UTC](https://community.squaredup.com/t/google-analytics/562/8 "2018-02-22T15:10:52Z")

</div>

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?
