-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into school-model-tweak
- Loading branch information
Showing
6 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict'; | ||
|
||
var Analytics = { | ||
|
||
tagManagerIsLoaded: false, | ||
|
||
EVENT_CATEGORY: 'PFC Dynamic Disclosure Tool Interaction', | ||
|
||
/** | ||
* Get data layer object. | ||
* @param {string} action Name of event. | ||
* @param {string} label DOM element label. | ||
* @param {string} category Type of event. | ||
* @param {Function} callback Function to call on GTM submission. | ||
* @param {number} timeout Callback invocation fallback time. | ||
* @returns {object} Data layer object. | ||
*/ | ||
getDataLayerOptions: function( action, label, category, callback, timeout ) { | ||
return { | ||
event: category || Analytics.EVENT_CATEGORY, | ||
action: action, | ||
label: label || '', | ||
eventCallback: callback, | ||
eventTimeout: timeout || 500 | ||
}; | ||
}, | ||
|
||
/** | ||
* Initialize the Analytics module. | ||
*/ | ||
init: function() { | ||
// detect if Google tag manager is loaded | ||
if ( window.hasOwnProperty( 'google_tag_manager' ) ) { | ||
Analytics.tagManagerIsLoaded = true; | ||
} else { | ||
var _tagManager; | ||
Object.defineProperty( window, 'google_tag_manager', { | ||
enumerable: true, | ||
configurable: true, | ||
get: function() { | ||
return _tagManager; | ||
}, | ||
set: function( value ) { | ||
_tagManager = value; | ||
Analytics.tagManagerIsLoaded = true; | ||
} | ||
} ); | ||
} | ||
}, | ||
|
||
/** | ||
* @name sendEvent | ||
* @kind function | ||
* | ||
* @description | ||
* Pushes an event to the GTM dataLayer. | ||
* @param {object} dataLayerOptions Type of event. | ||
*/ | ||
sendEvent: function( dataLayerOptions ) { | ||
var callback = dataLayerOptions.eventCallback; | ||
if ( Analytics.tagManagerIsLoaded ) { | ||
window.dataLayer.push( dataLayerOptions ); | ||
} else if ( callback && typeof callback === 'function' ) { | ||
callback(); // eslint-disable-line callback-return, inline-comments, max-len | ||
} | ||
}, | ||
|
||
/** | ||
* @name sendEvents | ||
* @kind function | ||
* | ||
* @description | ||
* Pushes multiple events to the GTM dataLayer. | ||
* | ||
* @param {array} eventsArray Array of event objects. | ||
*/ | ||
sendEvents: function( eventsArray ) { | ||
if ( Array.isArray( eventsArray ) ) { | ||
for ( var i = 0, len = eventsArray.length; i < len; i++ ) { | ||
Analytics.sendEvent( eventsArray[i] ); | ||
} | ||
} | ||
} | ||
|
||
}; | ||
|
||
Analytics.init(); | ||
|
||
module.exports = Analytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters