Skip to content

5. Automated Analytics Integrations

Jacob Burden edited this page Aug 18, 2016 · 1 revision

OpenShare contains fully-realized Google Anaytics and [Google Tag Manager] (https://developers.google.com/tag-manager/devguide) integrations. This speeds deployment of your Google Analytics tracking to your social buttons and, with a full Tag Manager implementation, allows you to pass even deeper sharing information to Google Analytics or allows you to fire other types of marketing or analytics tags through Google Tag Manager dataLayer events.

Analytics Integration Types and Deployment

OpenShare’s analytics integrations can automatically fire one or more of the following: Google Analytics Events, Google Anaytics Social Interactions, and Google Tag Manager DataLayer Messages. These functions are called upon clicking of OpenShare sharing buttons.

This tracking can be deployed within the loading of the OpenShare script by passing a data attribute to the script call named “data-open-share-analytics”. The value of the attribute determines the integration(s) loaded.

Data Attribute Analytics Integration
event [Google Analytics Event] (https://developers.google.com/analytics/devguides/collection/analyticsjs/events)
social [Google Analytics Social Interaction] (https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions)
tagManager [Google Tag Manager Message] (https://developers.google.com/tag-manager/devguide)

For example, to fire both a Google Analytics Event as well as a Google Analytics Social Interaction on each OpenShare click, load the OpenShare library like this:

<script data-open-share-analytics='event,social' src='bundle.js'></script>

JS API Functions

You can also call the function OpenShare.analytics and pass as an argument the same data attributes as above. To follow the example above, to load the Google Analytics Event and Google Analytics Social Interaction integrations, simple call:

OpenShare.analytics('event');
OpenShare.analytics('social');

Google Analytics Direct Integrations

OpenShare currently only works automatically with Google Universal Analytics (analytics.js).

The Google Analytics direct integrations rely on an initialized tracker (the Javascript function that operates Google Analytics) named 'ga'. This is the standard name for Google Analytics trackers. If your tracker is named something different, then you need to change the code within the OpenShare library for both the Google Analytics calls as well as the tracker checker function. If no tracker is found, the library periodically checks for it and fails after several attempts. This prevents issues where Google Analytics is loaded after the OpenShare button is clicked.

With Google Analytics Events, the following information is passed along to Google Analytics:

Google Analytics Event Variable OpenShare Value
eventCategory "OpenShare Click"
eventAction The name/action of the social network clicked
eventLabel The url of the shared resource or identifying information for non-sharing actions

With Google Analytics Social Interactions, the following information is passed along to Google Analytics:

Google Analytics Social Interaction Variable OpenShare Value
socialNetwork The name of the social network clicked
socialAction The name of the social action taken
socialTarget The url of the shared resource or identifying information for non-sharing actions

Google Tag Manager Integration

The Google Tag Manager integration relies on an array-typed variable called dataLayer existing within the document. If this variable does not exist, then OpenShare creates it. If you are using a different variable name than "dataLayer" for your dataLayer, then you need to adjust the OpenShare code with both this detection and the .push function to take advantage of the automatically dataLayer messaging feature.

The dataLayer message contains an event called “OpenShare Share”, which permits you to create a trigger based on this event. The dataLayer message also contains information related to the share itself: the resource shared, the type of social interaction, the social network, and in some cases extended information such as the current number of shares in that network.