Out of the box, Open SDG sends information to Google Analytics for certain events:

  • All page loads
  • User changes data tabs (Table, Chart, etc.)
  • User changes metadata tabs (National, Global, etc.)
  • User changes the contrast setting
  • User downloads a CSV file

Google Analytics ID

In order to turn on the analytics functionality, you must set the Google Analytics ID in the site repository's _config_prod.yml like so:

  ga_prod: 'paste ID here'

It is recommend to only put this in _config_prod.yml, and not in _config.yml, because you would not want to confuse your metrics by mixing staging and production together.

Customising the Google Analytics parameters

If you would like to change the Google Analytics parameters (category/action/label) that Open SDG sends, you can create a data file at this path in your site repository: data/autotrack.yml

The contents of this YAML file can override any tracked event, according to their "preset" value. For example:

  category: My category
  action: My action
  label: My label

Tracking new click events

You can track a new click event using either HTML or Javascript.

Tracking a click event with HTML

Here is an example of tracking a new click event using HTML, in a Jekyll page or layout:

Below is a call-to-action that we would like to track.

<a href="/my-url" {% include autotrack.html preset="my_preset" category="My category" action="My action" %}>
  My link

Tracking a click event with Javascript

Here is an example of tracking a new click event using Javascript:

<a href="/my-url" id="my-link">My link</a>

var attributes = opensdg.autotrack('my_preset', 'My category', 'My action');