Google Analytics Integration Guide

Step 1: Custom JS (Parent) – After Document Ready
Paste the below code at the bottom of “After Document Ready” in Custom JS (Parent), note the configuration option at top:
//********************************
//*** GOOGLE ANALYTICS - START ***
//********************************
//If you do not want us to auto-detect the tracking ID, then please enter yours for the UA_Tracking_ID value:
var UA_Tracking_ID = "UA-XXXXXXXX-Y";

api.GA = {};
api.GA.num_checks = 0;
api.GA.tracker = false;
api.GA.is_ga_classic = false;
api.GA.is_ga_universal = false;

var tryInitGADigioh = function() {
    if (window.ga && window.ga.create) {
        api.GA.is_ga_universal = true;
        DIGIOH_CUSTOM_JS.log('DIGIOH: Using Google Universal Analytics');

        if (!UA_Tracking_ID || UA_Tracking_ID === "UA-XXXXXXXX-Y") {
            api.GA.tracker = window.ga.getAll()[0];
        } else {
            api.GA.trackerArr = window.ga.getAll();
            if (api.GA.trackerArr && api.GA.trackerArr.length) {
                for (var i = 0; i < api.GA.trackerArr.length; i++) {
                    if (api.GA.trackerArr[i].get('trackingId') == UA_Tracking_ID) {
                        api.GA.tracker = api.GA.trackerArr[i];
                        DIGIOH_CUSTOM_JS.log('DIGIOH: Using GA Account: ' + api.GA.tracker.get('trackingId'));
                        break;
                    }
                }
            }
        }
    } else if (window._gaq) {
        api.GA.is_ga_classic = true;
        api.GA.tracker = window._gaq._getAsyncTracker();
        DIGIOH_CUSTOM_JS.log('DIGIOH: Using Google Classic Analytics');
    } else {
        DIGIOH_CUSTOM_JS.log('DIGIOH: Unable to find Google Analytics (Classic or Universal)');
    }
};

tryInitGADigioh();
if(!api.GA.tracker) {
    var initGADigiohInterval = setInterval(function(){
        if (api.GA.tracker || api.GA.num_checks >= 10) {
            clearInterval(initGADigiohInterval);
            if (api.GA.tracker) {
                DIGIOH_CUSTOM_JS.log('DIGIOH: Using Google Analytics, Tracker Found!');
            } else {
                DIGIOH_CUSTOM_JS.log('DIGIOH: NOT using Google Analytics (Classic OR Universal)!');
            }
        } else {
            api.GA.num_checks++;
            tryInitGADigioh();
        }
    }, 500);
}

api.GA.sendGAEvent = function(cat, act, lab, val) {
    if (api.GA.tracker) {
        if (typeof val !== 'undefined' && val !== null) {
            api.GA.tracker.send('event', cat, act, lab, val, {'nonInteraction': 1});
            DIGIOH_CUSTOM_JS.log('DIGIOH: Sent GA Event: ' + cat + ', ' + act + ', ' + lab + ', ' + val);
        } else {
            api.GA.tracker.send('event', cat, act, lab, 0, {'nonInteraction': 1});
            DIGIOH_CUSTOM_JS.log('DIGIOH: Sent GA Event: ' + cat + ', ' + act + ', ' + lab);
        }
    } else {
        DIGIOH_CUSTOM_JS.log('DIGIOH: Did NOT send GA Event, tracker not found!');
    }
};

api.GA.logEvent = function(s, act) {
    var label = s.lightbox_name + (s.is_variation ? ('[' + s.variation_name + ']') : '');
    api.GA.sendGAEvent('Digioh', act, label);
};

api.GA.logDisplay = function(s) {
    api.GA.logEvent(s, 'Box Display');
};

api.GA.logSubmit = function(s) {
    api.GA.logEvent(s, 'Box Submit');
};

api.GA.logRedirect = function(s) {
    api.GA.logEvent(s, 'Box Redirect');
};

tryInitGADigioh();

//********************************
//*** GOOGLE ANALYTICS - END   ***
//********************************
Step 2: Custom JS (Boxes) – After Display, After Submit, After Redirect
Paste each one of the 3 function calls below into 3 new snippets into Custom JS (Boxes) with the Event Trigger as indicated. You can include or exclude specific Box IDs, or leave fields blank to run on all boxes.
After Display:
api.GA.logDisplay(s);
After Submit:
api.GA.logSubmit(s);
After Redirect:
api.GA.logRedirect(s);
Step 3: Publish, and you are now logging events to GA!
Events will likely not appear same day in reports, though you can verify it is working immediately via the Real Time tab in GA.
  • Category: Digioh
  • Action: Box Display/Submit/Redirect
  • Label: Box Name [Variation Name]