Google Analytics Integration

Skip to end of metadata
Go to start of metadata

 

Gigya provides a Plug & Play solution for Google Analytics and Google Universal Analytics. If you have a basic working Google Analytics integration, and want to add social events tracking, just load the gigyaGAIntegration.js library in the relevant pages in your website.

Add the following line to the <HEAD> section of each page that you would like to include in your analytics:

<script type="text/javascript" src="http://cdn.gigya.com/js/gigyaGAIntegration.js" >

Note that the line above has to appear after Google Analytics, Universal Analytics and/or Google Tag Manager are loaded in the page. The Gigya integration code depends on the general Google Analytics code and may not function properly if the correct loading order is not maintained.

In addition, Gigya's GA integration only works with Google default trackers. It will not work with Google named trackers. For example:

 

Default Tracker

ga('create', 'UA-xxxxx-y', 'auto');

Named Tracker

ga('create', 'UA-xxxxx-y', 'auto', 'myTracker');

The Default Tracking Behavior

Gigya's plug & play solution has a default configuration, specifying which Gigya events will be tracked and how. Depending on which version of Google analytics you are using (Universal, or Non-Universal) varying methods are defined for tracking social interactions and other events: For Non-Universal analytics: the _trackSocial and _trackEvent methods; for Universal analytics, there is a single Send method that takes a hitType of social or event. Gigya's default configuration maps the social events to the Google tracking methods as specified below:

Tracking Social Interactions

The Gigya events that are mapped to the _trackSocial method or social hitType are: onSendDone, onFollowClicked. 
You will find the analytics of these events in the following section of your Google Analytics standard reports:

 

The following table specifies, per Gigya event, the data that we pass to the _trackSocial method:

Gigya EventTriggered Bynetwork parametersocialAction parameteropt_target parameteropt_pagePath parameter

onSendDone

The sharing related plugins:Provider 
(Note: If there is more than one provider, _trackSocial is called for each provider separately.)
"Gigya " + [plugin method name] + " - Share Published"
(e.g. "Gigya showShareUI - Share Published")
The current page URLNA
onFollowClickedsocialize.showFollowBarUIProvider"Gigya Follow - button clicked"The current page URLNA

Tracking Other Events

The Gigya events that are mapped to the _trackEvent method or event hitType are: onReactionClicked, onReactionUnclicked, onCommentSubmitted, onCommentVoted, onLogin, onLogout, onConnectionAdded, onConnectionRemoved.
You will find the analytics of these events in the following section of your Google Analytics standard reports:

 

 

The following table specifies, per Gigya event, the data that we pass to the _trackEvent method:

Gigya EventTriggered Bycategory Parameteraction Parameteropt_label Parameter
onReactionClicked socialize.showReactionsBarUI"Gigya Reaction Bar""Button Clicked"Reaction text
onReactionUnClicked socialize.showReactionsBarUI"Gigya Reaction Bar""Button UnClicked"Reaction text
onCommentSubmittedcomments.showCommentsUI"Gigya Comments" / "Gigya Reviews"
(Defined according to the value of the event's "mode" field which can be either "comments" or "reviews")
"Comment Published" / "Review Published"Comments streamID
onCommentVotedcomments.showCommentsUI"Gigya Comments" / "Gigya Reviews""Comment Voted" / "Review voted"Comments streamID
onLogin

socialize.login

socialize.showLoginUI

various plugins

 

Login source name
(e.g. "Gigya Login UI", "Gigya Comments", "Gigya Login API", etc.) 
"Social Login"Provider
onLogout

socialize.logout

various plugins

Logout source name"Logout"Provider

onConnectionAdded

socialize.addConnection,

socialize.showAddConnectionsUI

various plugins

Connect source name
(e.g. "Gigya Add Connection UI", "Gigya Comments", "Gigya Add Connection API", etc.) 
"Social Connection Added"Provider

onConnectionRemoved

socialize.removeConnection,

socialize.showAddConnectionsUI

various plugins

Remove connection source name"Social Connection Removed"Provider

Overriding the Default Behavior

Gigya defines an "Event Map", defining which Gigya events will be tracked and how. The default "Event Map" specifies the mapping that is elaborated in the tables above. You may override (or add to) the default "Event Map" by setting the customEventMap parameter of the Global Conf object. Learn more in Overriding the Default Event Map. You may also track events manually, as described in the Tracking Social Events section below. 

Live Example

Please check out our live Demo Site and refer to the Demo Site Implementation Guide.
The demo site uses Google Analytics for tracking page view and social events. The site includes implementation of Gigya's Social Login and several of Gigya's plugins: Share Bar pluginReactions pluginComments plugin, and more. The events that are triggered by these plugins are reported to Google Analytics.

Google Tag Manager

What is Google Tag Manager?

Google Tag Manager extends the functionality of Google's Universal Analytics by enabling the ability to track a virtually unlimited number of unique events on the pages of your website by assigning tags to the relevant pages. Google Tag Manager is not a replacement for Google Analytics, and is used in conjunction with it. When events are triggered using Google Tag Manager, you are then able to track them as you would any other events inside your existing Google Analytics Dashboard. Additionally, once you create the tag and add the relevant script to your website, you are then able to dynamically edit the events for the tag directly from within the GTM Dashboard without needing to update your site's code. For more information, see the Google Tag Manager events documentation.

Google Tag Manager - Example Code

This code example adds Gigya specific events for tracking within the Google Analytics Dashboard. You can add this code to your site by including reference to the Gigya Google Analytics Plug&Play Library at cdn.gigya.com/js/gigyaGAIntegration.js For more information on creating custom GTM events, see the Google Tag Manager events documentation.

<script>
/* cdn.gigya.com/js/gigyaGAIntegration.js moved into GTM */
     
if (typeof gigya == 'undefined') gigya = { isGigya: true };
if (!gigya.defaultEventMaps) gigya.defaultEventMaps = [];
     
// Support for Google Analytics
     
// analytics.js queue creation using "ga" object
(function (_win, _doc, _ga) {
    _win['GoogleAnalyticsObject'] = _ga;
    _win[_ga] = _win[_ga] || function () {
        (_win[_ga].q = _win[_ga].q || []).push(arguments);
    };
})(window, document, 'ga');
 
// Map gigya events to analytics.js events
( function () {
    var getCategoryFunction = function (apiName) {
        return function (e) {
            return (e.source ? 'Gigya ' + e.source : 'Gigya ' + apiName + ' API');
        };
    };
    var _ga_trackSocial = function (socialNetwork, actionDescription, actionURL, currentPageURL) {
        dataLayer.push({
            "event": "social",
            "socialNetwork": socialNetwork,
            "socialAction": actionDescription,
            "socialTarget": actionURL,
            "socialPagePath": currentPageURL,
            "eventId": "B991"
        });
        /* TBC - also send normal event*/
        dataLayer.push({
            "event": "onload_event_gigya",
            "eventCategory": category,
            "eventAction": actionDescription,
            "eventLabel": target,
            "eventValue": undefined,
            "eventNonInteractive": true, // Social event is interactive
            "eventId": "B991"});
    };
    var _ga_trackEvent = function (category, actionDescription, target, currentPageURL) {
        dataLayer.push({
            "event": "onload_event_gigya",
            "eventCategory": category,
            "eventAction": actionDescription,
            "eventLabel": target,
            "eventValue": undefined,
            "eventNonInteractive": false,
            "eventId": "B991"
        });
    };
    var onSendDone = function (a, b, c) {
        var arProviders = a.split(',');
        for (var i = 0; i < arProviders.length; i++) {
            _ga_trackSocial(arProviders[i], b, c);
        }
    };
    gigya.defaultEventMaps.push({
        defaultMethod: _ga_trackEvent,
        eventMap: [
            {
                events: "sendDone",
                method: onSendDone,
                args: ['$providers', 'Gigya $source - Share Published', '$targetURL', document.location.href]
            },
            {
                events: "followClicked", method: _ga_trackSocial,
                args: ['$button.provider', 'Gigya Follow - button clicked', '$button.actionURL', document.location.href]
            },
            {
                events: "reactionClicked",
                args: ['Gigya Reaction Bar', 'Button Clicked', '$reaction.text']
            },
            {
                events: "reactionUnclicked",
                args: ['Gigya Reaction Bar', 'Button Unclicked', '$reaction.text']
            },
            {
                events: "commentSubmitted",
                args: [
                    function (e) { return (e.mode == 'reviews' ? 'Gigya Reviews' : 'Gigya Comments') },
                    function (e) { return (e.mode == 'reviews' ? 'Review Published' : 'Comment Published') },
                    '$streamID'
                ]
            },
            {
                events: "commentVoted",
                args: [
                    function (e) { return (e.mode ==    'reviews' ? 'Gigya Reviews' : 'Gigya Comments') },
                    function (e) { return (e.mode == 'reviews' ? 'Review Voted' : 'Comment Voted') },
                    '$streamID'
                ]
            },
            {
                events: "login",
                args: [getCategoryFunction('Login'), 'Social Login', '$provider']
            },
            {
                events: "logout",
                args: [getCategoryFunction('Logout'), 'Logout']
            },
            {
                events: "connectionAdded",
                args: [getCategoryFunction('Add Connection'), 'Social Connection Added', '$provider']
            },
            {
               events: "connectionRemoved",
               args: [getCategoryFunction('Remove Connection'), 'Social Connection Removed', '$provider']
            }
        ]
    });
})();
</script>

Tracking Social Events

Gigya's Web SDK fires events to which you can catch and pass on to Google Analytics. Please refer to the Events guide, which shows how to handle events generated by Gigya.

For sample code showing how to track several events, please refer to Tracking Social Events.