2019-09-13 22:47:07 +12:00
|
|
|
(function(window) {
|
|
|
|
"use strict";
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
window.ls.container.get("view").add({
|
2021-01-18 19:29:26 +13:00
|
|
|
selector: "data-analytics",
|
2019-09-13 22:47:07 +12:00
|
|
|
controller: function(element) {
|
2021-01-18 23:29:05 +13:00
|
|
|
let action = element.getAttribute("data-analytics-event") || "click";
|
|
|
|
let doNotTrack = window.navigator.doNotTrack;
|
|
|
|
|
|
|
|
if(doNotTrack == '1') {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
element.addEventListener(action, function() {
|
2021-01-18 23:29:05 +13:00
|
|
|
let category =
|
2020-02-04 08:20:10 +13:00
|
|
|
element.getAttribute("data-analytics-category") || "undefined";
|
2021-01-18 23:29:05 +13:00
|
|
|
let label = element.getAttribute("data-analytics-label") || "undefined";
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
if (!ga) {
|
|
|
|
console.error("Google Analytics ga object is not available");
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
ga("send", {
|
|
|
|
hitType: "event",
|
|
|
|
eventCategory: category,
|
|
|
|
eventAction: action,
|
|
|
|
eventLabel: label
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(window);
|