Skip to content
Snippets Groups Projects
Commit 365bc2f5 authored by khawkins98's avatar khawkins98
Browse files

Improve script invocation, GA detection

parent 8794df00
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ function ebiFrameworkInvokeScripts() {
**/
document.addEventListener("DOMContentLoaded", function(event) {
var bodyData = document.body.dataset;
if (bodyData.ebiFrameworkInvokeScripts != false) {
if (bodyData["ebiframeworkinvokescripts"] != "false") {
ebiFrameworkInvokeScripts();
}
});
......@@ -15,14 +15,18 @@ var numberOfEbiGaChecks = 0;
var numberOfEbiGaChecksLimit = 2;
var lastGaEventTime = Date.now(); // track the last time an event was send (don't double send)
function ebiGaCheck() {
numberOfEbiGaChecks++;
try {
if (ga && ga.loaded) {
jQuery('body').addClass('google-analytics-loaded'); // Confirm GA is loaded, add a class if found
ebiGaInit();
} else {
if (numberOfEbiGaChecks <= numberOfEbiGaChecksLimit) {
setTimeout(ebiGaCheck, 900); // give a second check if GA was slow to load
}
}
} catch (err) {
if (numberOfEbiGaChecks < numberOfEbiGaChecksLimit) {
numberOfEbiGaChecks++;
if (numberOfEbiGaChecks <= numberOfEbiGaChecksLimit) {
setTimeout(ebiGaCheck, 900); // give a second check if GA was slow to load
}
}
......@@ -399,7 +403,7 @@ function invokeResponsiveMenuEBI() {
<script type="text/JavaScript">$(document).foundation();</script>
<script type="text/JavaScript">$(document).foundationExtendEBI();</script>
Background: https://github.com/ebiwd/EBI-Framework/issues/77
Background: https://github.com/ebiwd/EBI-Framework/issues/77
*/
var bodyData = $('body').data();
if (bodyData.foundationInvoke) {
......
......@@ -338,7 +338,13 @@ function ebiFrameworkInvokeScripts() {
ebiFrameworkCookieBanner();
}
// init
/* All scripts are automatically loaded, unless the page asked us not to.
* Configurable with a data attribute:
* <body data-ebiFrameworkInvokeScripts="false">
**/
document.addEventListener("DOMContentLoaded", function(event) {
ebiFrameworkInvokeScripts();
var bodyData = document.body.dataset;
if (bodyData["ebiframeworkinvokescripts"] != "false") {
ebiFrameworkInvokeScripts();
}
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment