Skip to content

Google Analytics

Cole Hudson edited this page Mar 6, 2019 · 3 revisions

Configure Google Analytics

Google Analytics can be set to give reports on each exhibit within the portal; however, the quickest way to get Analytics running is to simply edit the analytics template file (_analytics.html.erb.example) found in app/views/shared and rename it to _analytics.html.erb. Next, redeploy your Spotlight app running the following command within your repository's root directory: docker-compose -p spotlight -f docker-compose.yml up --build -d app. You won't get individual exhibit analytics with this method; if you're looking for that, then follow the directions below.

How to Install and Configure GA (for individual exhibit analytics)

This step can either be completed before you run your initial installation or after the site is up and running. If you choose to configure Google Analytics after you have launched your site, you need to run the following command (as the portal user) within the server at /opt/state-portal: docker-compose -p spotlight up --build -d app

  1. Setup your site within Google Analytics (please refer to Google Analytics documentation for how to do this.)
  2. Copy down your Tracking ID
  3. Follow these instructions for configuring OAuth and API access for your site: https://github.com/tpitale/legato/wiki/OAuth2-and-Google#registering-for-api-access
  4. Copy your p12 key into your lib/assets folder
  5. Edit the file: config/initializers/spotlight_initializer.rb
  6. Uncomment (aka remove #) in the following lines of the file:
 Spotlight::Engine.config.analytics_provider = 'Google Analytics'
 Spotlight::Engine.config.ga_pkcs12_key_path = 'lib/assets/NAME_OF_MY_FILE.p12'
 Spotlight::Engine.config.ga_web_property_id = 'UA-NOTANUMBER'
 Spotlight::Engine.config.ga_email = 'EXAMPLE@SOMETHING.iam.gserviceaccount.com'
  • analytics_provider can be 'Google Analytics'

  • ga_pkcs12_key_path is the p12 file that you copied to assets so the path should be 'lib/assets/NAME_OF_FILE'

  • ga_web_property_id is the tracking ID that you copied for step 2 'UA-SOMETHING'

  • ga_email is the gserviceaccount.com email addressed that you added to your Google Analytics site while enabling OAuth in setup 3. Put this in single quotes as well.

If you have already deployed the portal, do not forget to update your spotlight site (Please see the first paragraph in this section for details).