if (!window.AS) AS = {}; if (!window.autosweetGA) autosweetGA = {}; AS.pixel = { bodyText: null, doAnalyticsWork: function () { AS.pixel.loadGoogleAnalytics4API("G-FKXCGXSB0C"); }, doPixelWork: function () { if (document.readyState != "complete") { setTimeout(function () { AS.pixel.doPixelWork(); }, 250); } else { AS.pixel.bodyText = AS.pixel.getText(); } }, loadGoogleAnalytics4API: function (gaTrackingCode) { var gt = document.createElement("script"); gt.async = "async"; gt.src = "https://www.googletagmanager.com/gtag/js?id=" + gaTrackingCode; document.head.appendChild(gt); window.dataLayer = window.dataLayer || []; autosweetGA[gaTrackingCode] = function () {dataLayer.push(arguments);}; autosweetGA[gaTrackingCode]('js', new Date()); autosweetGA[gaTrackingCode]('config', gaTrackingCode); }, getText: function () { var textNodes = AS.pixel.getTextNodesIn(document.body); var textValues = []; for (var i = textNodes.length - 1; i >= 0 ; i--) { if (textNodes[i]) { textValues.push(textNodes[i].textContent); } } return textValues.join(" "); }, getTextNodesIn: function (elem) { var textNodes = []; if (elem) { for (var nodes = elem.childNodes, i = nodes.length; i--;) { var node = nodes[i], nodeType = node.nodeType; if (nodeType == 3) { textNodes.push(node); } else if (nodeType == 1 || nodeType == 9 || nodeType == 11) { textNodes = textNodes.concat(AS.pixel.getTextNodesIn(node)); } } } return textNodes; } }; AS.pixel.doAnalyticsWork(); AS.pixel.doPixelWork();