-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharealist-gtm.min.js
1 lines (1 loc) · 8.36 KB
/
arealist-gtm.min.js
1
window._arlg=window._arlg||new function(e){(e=e||{}).areas=e.areas||[],e.data_layer_name=e.data_layer_name||"dataLayer",e.polling_frequency=e.polling_frequency||3,e.impressions_event_name=e.impressions_event_name||"AreaList Impressions",e.clicks_event_name=e.clicks_event_name||"AreaList Clicks",e.impression_event_name=e.impression_event_name||"AreaList Impression",e.click_event_name=e.click_event_name||"AreaList Click",e.storage_key_name=e.storage_key_name||"AreaList_GTM";var i={on:{},areas:e.areas,impressions:[],clicks:[],seen:[],clicked:[],track:{impressions:!e.disable_impressions,clicks:!e.disable_clicks},clickable:"a, button, input, select, .btn, .button, [onclick], .dropdown, .dropdown-toggle, .clickable, label, *[data-target], i, textarea",snap:"<div class='arlg' style='position: absolute; z-index: 100000; top: {1}px; left: {2}px; width: {3}px; height: {4}px; box-shadow: inset 0px 0px 30px -3px rgba(194,31,31,1); background: white;'></div>",highlight:"<div class='arlgh' style='pointer-events: none; position: absolute; z-index: 100000; top: {2}px; left: {3}px; width: {4}px; height: {5}px;'>\n\t \t\t\t\t<div style='width: 100%; min-width: 200px; height: 20px; background-color: rgba(52,140,217,1); color: white; padding-left: 6px;'>{1}</div>\n\t \t\t\t\t<div style='width: 100%; height: {6}px; box-shadow: 0px 0px 13px 0px rgba(52,140,217,1); background: transparent;'></div>\n\t \t\t\t</div>",layer:e.data_layer_name};e.extend_clickable&&(i.clickable+=", "+e.extend_clickable);var t=window.jQuery,n=function(){e.debug&&([].unshift.call(arguments,"?? [AreaList GTM]"),console.log.apply(null,arguments))},s=function(){var e=arguments;return e[0].replace(/{(\d+)}/g,function(i,t){return void 0!==e[t]?e[t]:i})},o=function(){if(!window.localStorage)return n("save:","window.localStorage is not available...");if(e.disable_storage)return n("save:","global switch disable_storage is on, not persisting...");var t={url:location.href,path:location.pathname,impressions:i.impressions,clicks:i.clicks};localStorage.setItem(e.storage_key_name,JSON.stringify(t)),n("save:",t)},a=function(e){n("reset:",e||"all"),e&&"impressions"!=e||(i.seen=i.seen.concat(i.impressions),i.impressions=[]),e&&"clicks"!=e||(i.clicked=i.clicked.concat(i.clicks),i.clicks=[]),o()},l=function(e,i){var t=e.options&&e.options.hastitle,n=i.find(e.title).length?i.find(e.title).first():null;!n&&i.attr(e.title)&&(n=i.attr(e.title));try{!n&&i.find("["+e.title+"]")&&(n=i.find("["+e.title+"]").first().attr(e.title))}catch(e){}return n||(n=i.parent().parent().parent().find(e.title).first()),!n&&t&&(n=i),n&&n.text&&(n=n.text().trim().replace(/[\r\n\t]+/g," ").replace(/ +/g," ")),n&&n.length>50&&(n=n.substr(0,50)+".."),n},r=function(a,r){"poll"!=a&&n("collect:",a);var c=[];i.areas.map(function(o){var a=t(o.handle),r=o.options&&o.options.hastitle;0!=a.length&&(o.options&&o.options.single&&a.length>1||o.options&&o.options.multiple&&1==a.length||a.each(function(){var p=t(this),m={name:o.name,title:null,list:o.list||e.list||location.pathname,cat:o.cat||e.cat||document.title};if(o.disabled)return n("collect area disabled:",m.name,o.handle);if(o.title){var u=l(o,p);if(u)m.title=u;else if(r)return}var h=i.impressions.some(function(e){return e.name==m.name&&e.title==m.title}),g=i.seen.some(function(e){return e.name==m.name&&e.title==m.title});if(!h&&!g&&(p.isVis()||o.options&&!o.options.novischeck)&&(p.inView()||o.options&&!o.options.novischeck)&&(!o.options||-1==o.options.clickable||t(a).find(i.clickable).length)){if(i.track.impressions&&(i.impressions.push(m),c.push(m),e.disable_storage&&d("impression",m)),e.debug){var f=p.get(0).getBoundingClientRect(),v=s(i.snap,parseInt(f.y)+t(document).scrollTop(),parseInt(f.x)+t(document).scrollLeft(),parseInt(f.width),parseInt(f.height));t("body").prepend(v),t(".arlg").fadeOut(600),setTimeout(function(){t(".arlg").remove()},600)}n("collect impression:",JSON.stringify(m),i.impressions)}}))}),c.length&&(o(),h("impression",c))},c=function(s){var r=t(s.target),c=[];(r.is(i.clickable)||r.closest(i.clickable).length)&&(i.areas.map(function(s){if(r.closest(s.handle).length){var o=r.closest(s.handle),a=s.options&&s.options.hastitle;if(s.disabled)return n("click area disabled:",s.name);if(s.options&&s.options.single&&t(s.handle).length>1)return n("click area condition is single match so skipping:",s.name,s.handle);if(s.options&&s.options.multiple&&1==t(s.handle).length)return n("click area condition is multiple match so skipping:",s.name,s.handle);var p=s.options&&s.options.noclickdedupe,m={name:s.name,title:null,list:s.list||e.list||location.pathname,cat:s.cat||e.cat||document.title};if(s.title){var u=l(s,o);if(u)m.title=u;else if(a)return}var h=!p&&i.clicked.some(function(e){return e.name==m.name&&e.title==m.title});if(h)return n("collect area click exists and dedup is on:",JSON.stringify(m),s.handle);h=i.impressions.some(function(e){return e.name==m.name&&e.title==m.title});var g=i.seen.some(function(e){return e.name==m.name&&e.title==m.title});h||g||!i.track.impressions||(i.impressions.push(m),n("collect impression on click:",JSON.stringify(m),i.impressions),e.disable_storage&&d("impression",m)),n("collect click:",JSON.stringify(m),i.clicks),i.track.clicks&&(i.clicks.push(m),c.push(m),e.disable_storage&&d("click",m))}}),c.length&&(o(),h("click",c,s),e.disable_storage&&(d("clicks"),a("clicks"))))},p=function(i){var t=!1;return window.localStorage&&(t=localStorage.getItem(e.storage_key_name))&&(t=JSON.parse(t)),n("fetch:",i,"from",t),t?void 0!==t[i]?t[i]:void n("fetch error: no such thing as",i):(n("fetch found no store or in-memory tracker, returning null"),[])},d=function(t,s){if("impressions"==t){if(!i.impressions.length)return;var o=i.impressions.map(function(e,i){var t=e.title?e.name+": "+e.title:e.name;return{id:t,name:t,category:e.cat||"AreaList",list:e.list||p("path"),position:i+1}});n("push impressions:",o),!window[i.layer]||window[i.layer].push({event:e.impressions_event_name,ecommerce:{impressions:o}})}if("clicks"==t){if(!i.clicks.length)return;var a=i.clicks.map(function(e,i){var t=e.title?e.name+": "+e.title:e.name;return{id:t,name:t,category:e.cat||"AreaList",list:e.list||p("path"),position:i}});n("push clicks:",a),!window[i.layer]||window[i.layer].push({event:e.clicks_event_name,ecommerce:{click:{actionField:{list:a[0].list||location.pathname},products:a}}})}"impression"==t&&(n("push impression:",s),!window[i.layer]||window[i.layer].push({event:e.impression_event_name,arealist:s})),"click"==t&&(n("push click:",s),!window[i.layer]||window[i.layer].push({event:e.click_event_name,arealist:s}))},m=function(e,i){var n="";i&&(n=m(t(e).parent(),!1)+" > "),n+=t(e).get(0).tagName.toLowerCase();var s=t(e).attr("id");s&&(n+="#"+s);var o=t(e).attr("class");return o&&(n+="."+o.split(" ").slice(0,2).join(".")),n},u=function(){if(i.mouse){var e=document.elementFromPoint(i.mouse.x,i.mouse.y);if(e&&i.highlighted!=e){var n=e.getBoundingClientRect();if(!(n.x<=0||n.y<=0)){i.highlighted=e;var o=m(e,!0);t(".arlgh").remove(),t("body").prepend(s(i.highlight,o,n.y+t(document).scrollTop()-20,n.x+t(document).scrollLeft(),n.width,n.height+20,n.height))}}}},h=function(e,t,s){i.on[e]&&i.on[e].forEach(function(e){n("trigger:",t),e(s?{name:t.name,title:t.title,event:s}:t)})};t?(t.fn.inView=function(){var e=t(this).offset().top,i=e+t(this).outerHeight(),n=t(window).scrollTop(),s=n+t(window).height();return i>n&&e<s},t.fn.isVis=function(){return t(this).is(":visible")&&"hidden"!=t(this).css("visibility")&&"0"!=t(this).css("opacity")},t(window).on("load",function(){i.impressions=p("impressions"),d("impressions"),i.clicks=p("clicks"),d("clicks"),a(),i.seen=[],i.clicked=[],r("load")}),t(document).on("click",c),n("init: now live with the following settings:",e,"inside",location.href),i.areas.length&&(i._poll=setInterval(function(){r("poll")},1e3*parseInt(e.polling_frequency)),n("init: polling activated for "+i.areas.length+" defined areas")),e.disable_storage&&(window.addEventListener("beforeunload",function(i){d("impressions"),localStorage.removeItem(e.storage_key_name)}),n("init: settings.disable_storage is on, will push impressions on beforeuload, instantly for clicks")),e.debug&&(document.addEventListener("mousemove",function(e){i.mouse=e},!1),i._highlight=setInterval(u,500),n("init: debug mode highlighting enabled")),delete window.arealist_config):n("aborting due to lack of jQuery");var g={on:function(e,t){n("_arlg.on",e,t),i.on[e]=i.on[e]||[],i.on[e].push(t)},reset:a,data:function(){return i}};return g}(window.arealist_config);