/** * @constant * @type {string} prefix to all log events specific to the analytics logic, printed to the console. */ var ANALYTICS__LOGGER_PREFIX = "[Analytics] -"; /** * Controller model, providing access to the data layer on a global scale. *
* Allows to enable debugger logger, providing console logs on each event. * * @constructor * @class */ AnalyticsController = function () { this.dataLayer = new DataLayer(); var __debugAnalytics = sessionStorage.getItem('analytics.Debugger.active'); if (!__debugAnalytics) { __debugAnalytics = 'false'; } this.enableDebugger = function () { __debugAnalytics = 'true'; sessionStorage.setItem('analytics.Debugger.active', 'true'); }; this.disbaleDebugger = function () { __debugAnalytics = 'false'; sessionStorage.removeItem('analytics.Debugger.active'); }; this.isDebug = function () { return Boolean(__debugAnalytics === "true"); }; }; /** * Initialization of the {@link AnalyticsController} * on custom event 'launch.libraryLoaded' executed by the launch object reference, * and thereby providing a {@link DataLayer} on a global scale. * The global scale is bound to the namespace 'window.analytics'. *
* Collection of event bindings, specific to the analytics relevant interactions of the page. */ (function (factory) { window.addEventListener('launch.libraryLoaded', function () { factory(window.jQuery); }, false); })(function initTracking($) { if (typeof _satellite === 'undefined') { console.info("%s '_satellite' object is not available. Aborting initialization of event binding and analytics data layer", ANALYTICS__LOGGER_PREFIX); return; } /* --- init custom controller --- */ window.analytics = new AnalyticsController(); /* --- init custom event handler --- */ var eventHandler = new AnalyticsEventHandler(); /* --- global event information, which should be provided with every tracking event if necessary --- */ var globalInfo = {}; //retrieve global information logic here. analytics.dataLayer.addGlobalEventData(globalInfo); /* --- specific analytics event binding starts here --- */ // sample event binding window.addEventListener('some.tracking.event', function (event) { var eventInfo = analytics.dataLayer.createNewEvent(); eventHandler['someTrackingEvent'].handle(event, eventInfo); analytics.dataLayer.addEventAndExecute(eventInfo); }); });