UNPKG

asd-javascript-sdk

Version:

official analysysAgent javascript sdk

2 lines (1 loc) 7.2 kB
!function(){"use strict";var t=window,e={};function r(t){var r=typeof t;return"object"===r?e[Object.prototype.toString.call(t)]:r}function n(t){return"string"===r(t)}function i(t){return Array.isArray(t)}function o(t){return"object"===r(t)}["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","HTMLCollection"].map((function(t){e["[object "+t+"]"]=t.toLowerCase()}));var u=function(t){return t instanceof HTMLElement};function a(t){return"htmlcollection"===r(t)}function s(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];for(var n=0;n<e.length;n++){var i=e[n];if(o(i))for(var u in i)t[u]=i[u]}return t}var c=function(t,e){return t&&t.getAttribute?t.getAttribute(e):null};function f(t){var e=t.tagName.toLowerCase();return function(t){if(n(t)&&t.length>255)return t.slice(0,254)+"$";return t}(("input"===e&&["button","submit"].indexOf(t.type)>-1?t.value||"":"img"===e?c(t,"alt")||c(t,"title")||"":t.textContent||t.title).trim())}var l=function(t,e,r){var n=s({},r),i=0;if(u(t)||t instanceof SVGElement)for(;t.parentNode;){if(e(t,i))return t;if(i++,t=t.parentNode,n.root&&t===n.root){e&&e(t,i);break}}};function v(t,e){if(t){if(u(t)&&t===e)return!0;if(i(t))for(var n=0;n<t.length;n++){var o=t[n];if(u(o)&&o===e)return!0;if(a(o))for(var s=0;s<o.length;s++)if(o[s]===e)return!0}if("function"===r(t))return v(t(),e)}return!1}function d(t){return null!==c(t,"data-ark-exposure")}var p={valid_time:300,property:{},exposure_click:!1,multiple:!1,element_list:[]},m=new WeakMap,g=new MutationObserver((function(t){for(var e=0;e<t.length;e++){x(t[e].addedNodes)}})),h=new IntersectionObserver((function(e){for(var i=function(i){var o=e[i],a=o.target;if(o.intersectionRatio>0&&!1===m.get(a)){var v=setTimeout((function(){!function(e){var r=t.AnalysysAgent,i=c(e,"data-ark-exposure");if(i)try{i=JSON.parse(i)||{}}catch(t){i={}}else i={};if(!i.exposure_id){var o=(a=e,d=s({full:!1,mode:"loose",endTag:[]},v),g="",l(a,(function(t){var e=t.id,r=t.tagName.toLowerCase(),i="";if(d.endTag.indexOf(r)>-1&&(g=""),u(t)){if(e&&!d.full)i="//"+r+'[@id="'+e+'"]';else{var o=t.parentNode?Array.from(t.parentNode.children).filter((function(e){var r=e.tagName===t.tagName,i=e.className;if(i&&n(i)){if("ordinary"===d.mode)return r&&i.indexOf(t.classList[0])>-1;if("strict"===d.mode)return r&&i===t.className}return r})):[],a=o.length>1?"["+(o.indexOf(t)+1)+"]":"",s="";"ordinary"===d.mode&&t.classList[0]&&(s='[contains(@class,"'+t.classList[0]+'")]'),"strict"===d.mode&&t.className&&(s='[@class="'+t.className+'"]'),i="/"+r+s+a}g=i+g}if(!d.full&&e)return!0})),g);i.exposure_id=function(t,e){function r(t,e){return t<<e|t>>>32-e}function n(t,e){var r,n,i,o,u;return i=2147483648&t,o=2147483648&e,u=(1073741823&t)+(1073741823&e),(r=1073741824&t)&(n=1073741824&e)?2147483648^u^i^o:r|n?1073741824&u?3221225472^u^i^o:1073741824^u^i^o:u^i^o}function i(t,e,i,o,u,a,s){return t=n(t,n(n(function(t,e,r){return t&e|~t&r}(e,i,o),u),s)),n(r(t,a),e)}function o(t,e,i,o,u,a,s){return t=n(t,n(n(function(t,e,r){return t&r|e&~r}(e,i,o),u),s)),n(r(t,a),e)}function u(t,e,i,o,u,a,s){return t=n(t,n(n(function(t,e,r){return t^e^r}(e,i,o),u),s)),n(r(t,a),e)}function a(t,e,i,o,u,a,s){return t=n(t,n(n(function(t,e,r){return e^(t|~r)}(e,i,o),u),s)),n(r(t,a),e)}function s(t){var e,r="",n="";for(e=0;e<=3;e++)r+=(n="0"+(t>>>8*e&255).toString(16)).substr(n.length-2,2);return r}var c,f,l,v,d,p,m,g,h,x;for(c=function(t){for(var e,r=t.length,n=r+8,i=16*((n-n%64)/64+1),o=Array(i-1),u=0,a=0;a<r;)u=a%4*8,o[e=(a-a%4)/4]=o[e]|t.charCodeAt(a)<<u,a++;return u=a%4*8,o[e=(a-a%4)/4]=o[e]|128<<u,o[i-2]=r<<3,o[i-1]=r>>>29,o}(t),m=1732584193,g=4023233417,h=2562383102,x=271733878,f=0;f<c.length;f+=16)l=m,v=g,d=h,p=x,m=i(m,g,h,x,c[f+0],7,3614090360),x=i(x,m,g,h,c[f+1],12,3905402710),h=i(h,x,m,g,c[f+2],17,606105819),g=i(g,h,x,m,c[f+3],22,3250441966),m=i(m,g,h,x,c[f+4],7,4118548399),x=i(x,m,g,h,c[f+5],12,1200080426),h=i(h,x,m,g,c[f+6],17,2821735955),g=i(g,h,x,m,c[f+7],22,4249261313),m=i(m,g,h,x,c[f+8],7,1770035416),x=i(x,m,g,h,c[f+9],12,2336552879),h=i(h,x,m,g,c[f+10],17,4294925233),g=i(g,h,x,m,c[f+11],22,2304563134),m=i(m,g,h,x,c[f+12],7,1804603682),x=i(x,m,g,h,c[f+13],12,4254626195),h=i(h,x,m,g,c[f+14],17,2792965006),m=o(m,g=i(g,h,x,m,c[f+15],22,1236535329),h,x,c[f+1],5,4129170786),x=o(x,m,g,h,c[f+6],9,3225465664),h=o(h,x,m,g,c[f+11],14,643717713),g=o(g,h,x,m,c[f+0],20,3921069994),m=o(m,g,h,x,c[f+5],5,3593408605),x=o(x,m,g,h,c[f+10],9,38016083),h=o(h,x,m,g,c[f+15],14,3634488961),g=o(g,h,x,m,c[f+4],20,3889429448),m=o(m,g,h,x,c[f+9],5,568446438),x=o(x,m,g,h,c[f+14],9,3275163606),h=o(h,x,m,g,c[f+3],14,4107603335),g=o(g,h,x,m,c[f+8],20,1163531501),m=o(m,g,h,x,c[f+13],5,2850285829),x=o(x,m,g,h,c[f+2],9,4243563512),h=o(h,x,m,g,c[f+7],14,1735328473),m=u(m,g=o(g,h,x,m,c[f+12],20,2368359562),h,x,c[f+5],4,4294588738),x=u(x,m,g,h,c[f+8],11,2272392833),h=u(h,x,m,g,c[f+11],16,1839030562),g=u(g,h,x,m,c[f+14],23,4259657740),m=u(m,g,h,x,c[f+1],4,2763975236),x=u(x,m,g,h,c[f+4],11,1272893353),h=u(h,x,m,g,c[f+7],16,4139469664),g=u(g,h,x,m,c[f+10],23,3200236656),m=u(m,g,h,x,c[f+13],4,681279174),x=u(x,m,g,h,c[f+0],11,3936430074),h=u(h,x,m,g,c[f+3],16,3572445317),g=u(g,h,x,m,c[f+6],23,76029189),m=u(m,g,h,x,c[f+9],4,3654602809),x=u(x,m,g,h,c[f+12],11,3873151461),h=u(h,x,m,g,c[f+15],16,530742520),m=a(m,g=u(g,h,x,m,c[f+2],23,3299628645),h,x,c[f+0],6,4096336452),x=a(x,m,g,h,c[f+7],10,1126891415),h=a(h,x,m,g,c[f+14],15,2878612391),g=a(g,h,x,m,c[f+5],21,4237533241),m=a(m,g,h,x,c[f+12],6,1700485571),x=a(x,m,g,h,c[f+3],10,2399980690),h=a(h,x,m,g,c[f+10],15,4293915773),g=a(g,h,x,m,c[f+1],21,2240044497),m=a(m,g,h,x,c[f+8],6,1873313359),x=a(x,m,g,h,c[f+15],10,4264355552),h=a(h,x,m,g,c[f+6],15,2734768916),g=a(g,h,x,m,c[f+13],21,1309151649),m=a(m,g,h,x,c[f+4],6,4149444226),x=a(x,m,g,h,c[f+11],10,3174756917),h=a(h,x,m,g,c[f+2],15,718787259),g=a(g,h,x,m,c[f+9],21,3951481745),m=n(m,l),g=n(g,v),h=n(h,d),x=n(x,p);return 32===e?s(m)+s(g)+s(h)+s(x):s(g)+s(h)}(o)}var a,v,d,g;i.exposure_content||(i.exposure_content=f(e));var x=s({},p.property,i);r.track("exposure_points",x),e.exposureAttrs=x,p.multiple||(m.set(e,!0),h.unobserve(e));p.multiple>0&&(m.set(e,!0),setTimeout((function(){m.set(e,!1)}),p.multiple))}(a)}),p.valid_time);m.set(a,v)}if(0===o.intersectionRatio){var d=m.get(a);"number"===r(d)&&(clearTimeout(d),m.set(a,!1))}},o=0;o<e.length;o++)i(o)}),{threshold:[.01]});function x(t,e){for(var r=0;r<t.length;r++){var n=t[r];1===n.nodeType&&(m.has(n)||!d(n)&&!v(p.element_list,n)||(h.observe(n),m.set(n,!1)),n.childNodes.length>0&&x(n.childNodes))}}function y(){var e=t.AnalysysAgent;s(p,e.config.exposure),x(function(t){var e=[];if(i(t))for(var r=0;r<t.length;r++){var n=t[r];if(u(n)&&e.push(n),a(n))for(var o=0;o<n.length;o++)e.push(n[o])}return e}(p.element_list)),x(document.querySelectorAll("[data-ark-exposure]")),g.observe(document.body,{childList:!0,subtree:!0}),p.exposure_click&&document.addEventListener("click",(function(t){var r=t.target,n=r.exposureAttrs;n&&!r.isExposureClick&&(e.track("exposure_click",n),r.isExposureClick=!0)}))}var b=t.location.href;b.indexOf("visual=true")<0&&b.indexOf("arkheatmap=true")<0&&function e(){var r=t.AnalysysAgent;r&&r.isInit?y():setTimeout(e,300)}()}();