s
sunknown
javascript
2 years ago
9.7 kB
16
Indexable
(function () {
try {
var debug = 0;
var variation_name = "";
var scrollMetric = {
scroll25: false,
scroll50: false,
scroll75: false,
scroll100: false,
};
function waitForElement(selector, trigger, delayInterval, delayTimeout) {
var interval = setInterval(function () {
if (
document &&
document.querySelector(selector) &&
document.querySelectorAll(selector).length > 0
) {
clearInterval(interval);
trigger();
}
}, delayInterval);
setTimeout(function () {
clearInterval(interval);
}, delayTimeout);
}
function live(selector, event, callback, context) {
/****Helper Functions****/
// helper for enabling IE 8 event bindings
function addEvent(el, type, handler) {
if (el.attachEvent) el.attachEvent("on" + type, handler);
else el.addEventListener(type, handler);
}
// matches polyfill
this.Element &&
(function (ElementPrototype) {
ElementPrototype.matches =
ElementPrototype.matches ||
ElementPrototype.matchesSelector ||
ElementPrototype.webkitMatchesSelector ||
ElementPrototype.msMatchesSelector ||
function (selector) {
var node = this,
nodes = (node.parentNode || node.document).querySelectorAll(selector),
i = -1;
while (nodes[++i] && nodes[i] != node);
return !!nodes[i];
};
})(Element.prototype);
// live binding helper using matchesSelector
function live(selector, event, callback, context) {
addEvent(context || document, event, function (e) {
var found,
el = e.target || e.srcElement;
while (el && el.matches && el !== context && !(found = el.matches(selector))) el = el.parentElement;
if (el && found) callback.call(el, e);
});
}
live(selector, event, callback, context);
}
function init() {
if (!document.querySelector('.eg-events-added')) {
document.body.classList.add('eg-events-added');
window.addEventListener("scroll", observeScroll);
// clicks ( variation )
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="overview"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - overview');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="performance"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - performance');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="keyFacts"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - keyFacts');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="holdingsAllocation"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - holdingsAllocation');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="researchResources"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - researchResources');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="distributions"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - distributions');
});
live('html body .eg-tab-container_new .eg-tab-cta[data-tab-name="announcements"]', 'click', function () {
sendEvtOpt('Clicks on the page menu at the top of the page - announcements');
});
live('html body .eg-quick-cta .eg-invest-quick-link:nth-child(1),html body .eg-invest-cta_hero,html body .eg-tab-wrapper_new .eg-new-content-block .eg-investing-block .eg-invest-cta', 'click', function () {
sendEvtOpt('Clicks on invest cta');
});
live('html body .eg-quick-cta .eg-invest-quick-link:nth-child(2),html body .eg-factsheet-cta_hero', 'click', function () {
sendEvtOpt('Clicks on factsheet cta');
});
live('html body .eg-quick-cta .eg-invest-quick-link:nth-child(3),html body .eg-infopack-cta_hero', 'click', function () {
sendEvtOpt('Clicks on infopack cta');
});
// clicks ( control )
live('[href="#overview"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - overview');
});
live('[href="#key-facts"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - keyfacts');
});
live('[href="#holdings-and-allocation"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - holdings and allocation');
});
live('[href="#performance"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - performance');
});
live('[href="#distributions"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - distributions');
});
live('[href="#announcements"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - announcements');
});
live('[href="#research"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - research');
});
live('[href="#resources"]', 'click', function () {
sendEvtOpt('Clicks on the page menu on the left side - resources');
});
live('html body .fund-nav>div>div:first-child a', 'click', function () {
sendEvtOpt('Clicks on Factsheet CTA');
});
live('html body .fund-nav>div>button:nth-child(2),html body .fund-landing .dropdown-menu-container #request-menu>button:first-child', 'click', function () {
sendEvtOpt('Clicks on Request infopack CTA');
});
live('html body .fund-nav>div>button:nth-child(3),html body .fund-landing .dropdown-menu-container #request-menu>button:nth-child(2)', 'click', function () {
sendEvtOpt('Clicks on request call CTA');
});
if (window.innerWidth < 767) {
waitForElement('html body .fund-landing .dropdown-menu-container', function () {
const parent = document.querySelector('html body .fund-landing .dropdown-menu-container').parentElement;
const dropdownEl = document.querySelector('html body .fund-landing .dropdown-menu-container');
parent.children[0].addEventListener('click', function () {
sendEvtOpt('Clicks on Factsheet CTA');
});
}, 50, 15000);
}
}
}
function sendEvtOpt(evName, isScrollMetric) {
if (isScrollMetric) evName = "_scrolls_" + evName + "_percent_of_page";
console.log("metric triggered: " + evName);
}
function observeScroll() {
var h = document.documentElement,
b = document.body,
st = "scrollTop",
sh = "scrollHeight";
if (!scrollMetric.scroll100 && h && b) {
var percentage = ((h[st] || b[st]) / ((h[sh] || b[sh]) - h.clientHeight)) * 100;
if (!scrollMetric.scroll25 && percentage > 25) {
scrollMetric.scroll25 = true;
sendEvtOpt("25", true);
}
if (!scrollMetric.scroll50 && percentage > 50) {
scrollMetric.scroll50 = true;
sendEvtOpt("50", true);
}
if (!scrollMetric.scroll75 && percentage > 75) {
scrollMetric.scroll75 = true;
sendEvtOpt("75", true);
}
if (percentage > 99) {
scrollMetric.scroll100 = true;
sendEvtOpt("100", true);
window.removeEventListener("scroll", observeScroll);
}
}
}
waitForElement('body', init, 50, 15000);
} catch (e) {
if (debug) console.log(e, "error in Test" + variation_name);
}
})();
Editor is loading...