// push contentLocale and pageName from GA dataLayer array of object, finding for (var i = 0; i < dataLayer.length; ++ i) { if (typeof dataLayer[i].contentLocale != 'undefined' && typeof dataLayer[i].pageName != 'undefined') { var contentLocale = dataLayer[i].contentLocale, pageName = dataLayer[i].pageName; } } // detect Android and Chrome var detect = avm.require("avast.detect"), detecting = detect(); if (detecting.os.isAndroid && detecting.browser.isChrome) { // GA tracking - banner accepted OR dismiss, https://butr.avast.com/browse/WAN-256 var pagePath = window.location.pathname; var bannerName = 'android-smart-banner'; if ('serviceWorker' in navigator) { window.addEventListener('load', function() { navigator.serviceWorker.register('../asb-service-worker.js') .then(function(r) { console.log('registered service worker'); // when service worker is registered dataLayer.push({ 'event' : 'VirtualPageview', 'virtualPageURL' : pagePath + '/' + bannerName, 'pageName' : pageName, 'contentLocale' : contentLocale }); }).catch(function(error) { console.log(error); }); window.addEventListener('beforeinstallprompt', function(e) { e.userChoice.then(function(choiceResult) { console.log(choiceResult.outcome); // when user tap/clik to INSTALL or close dataLayer.push({ 'event' : 'websiteEvent', 'eventCategory' : 'Website', 'eventAction' : choiceResult.outcome, 'eventLabel' : pagePath + '/android-smart-banner', 'eventNonInteraction' : 'false' }); }); }); }); } else { console.warn('Not supported in this browser.'); // GA tracking - Not supported in this browser dataLayer.push({ 'event' : 'websiteEvent', 'eventCategory' : 'Website', 'eventAction' : 'BrowserNotSupported', 'eventLabel' : pagePath + '/android-smart-banner', 'eventNonInteraction' : 'false' }); } }