Created
January 16, 2023 14:08
-
-
Save BorisChumichev/a936b6945dd11e3018e6a508b85b1c10 to your computer and use it in GitHub Desktop.
snitch-mini-apps-0.0.16-with-scroll-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createSnitch=function(){"use strict";var e=[],n=[];window.addEventListener("scroll",(function(){var t=window.scrollY/(Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)-window.innerHeight),r=10*Math.round(100*t/10);~e.indexOf(r)||(e.push(r),n.forEach((function(e){return e(r)})))}));function t(){var t;return{setEventHandler:function(e){t=e},onInit:function(){var e;e=function(e){return t("scroll",{depthPercent:e})},~n.indexOf(e)||n.push(e)},beforeCaptureEvent:function(n){"locationChange"!==n&&"screenChange"!==n||(e=[])}}}function r(){for(var e="",n="useandom26T198340PX75pxJACKVERYMINDBUSHWOLFGQZbfghjklqvwyzrict",t=n.length,r=0;r<32;r++)e+=n.charAt(Math.floor(Math.random()*t));return e}var a="isdp:sid",o="isdp:scnt",i="isdp:sutm",c="isdp:livts",l="isdp:ssts";function s(){return localStorage.getItem(a)}function u(e){localStorage.setItem(c,e.toString())}var d=/,+$/;function v(e){var n=new URL(e),t=new URL(e.replace(n.search,"").replace("#","?"));return["utm_source","utm_medium","utm_campaign","utm_content","utm_term"].map((function(e){return n.searchParams.get(e)||t.searchParams.get(e)||""})).join(",").replace(d,"")}function f(){var e;function n(){return Date.now()-parseInt(localStorage.getItem(c),10)>18e5}function t(){var n,t,c;n=r(),localStorage.setItem(a,n),t=Date.now(),localStorage.setItem(l,Math.floor(t).toString()),c=v(location.href),localStorage.setItem(i,c),localStorage.setItem(o,(parseInt(localStorage.getItem(o)||"0",10)+1).toString()),u(Date.now()),e("sessionStart")}return{setEventHandler:function(n){e=n},onInit:function(){var e,r=null===s(),a=(e=window.location.href,/utm_(source|medium|campaign|content|term)=[^&#]+/.test(e)),o=n();(r||a||o)&&t()},beforeCaptureEvent:function(){n()&&t(),u(Date.now())},getEventPayloadParams:function(){return{sid:s(),scnt:parseInt(localStorage.getItem(o),10),set:Date.now()-parseInt(localStorage.getItem(l),10),sutm:localStorage.getItem(i)}}}}var m="VKWebAppTrackEvent",g="undefined"!=typeof window,p=Boolean(g&&window.AndroidBridge),h=Boolean(g&&window.webkit&&window.webkit.messageHandlers&&window.webkit.messageHandlers.VKWebAppClose),w=g&&!p&&!h,E=g?window.AndroidBridge:void 0,I=h?window.webkit.messageHandlers:void 0;function _(){var e=new URL(location.href).searchParams.get("vk_user_id")||"anonymous";return{sendEvent:function(n,t){if(t)for(var r=0,a=Object.keys(t);r<a.length;r++){var o=a[r];null===t[o]&&(t[o]="null"),void 0===t[o]&&(t[o]="undefined"),"string"!=typeof t[o]&&(t[o]=t[o].toString())}var i;i={custom_user_id:e,event_name:n,event_params:t},E&&E[m]?E[m](JSON.stringify(i)):I&&I[m]&&"function"==typeof I[m].postMessage?I[m].postMessage(i):w&&parent.postMessage({handler:m,params:i,type:"vk-connect",webFrameId:void 0,connectVersion:"2.5.0"},"*")}}}var P=function(){return(P=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var a in n=arguments[t])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e}).apply(this,arguments)},y=function(e){return function(n){var t=new URL(n);return Object.entries(e).reduce((function(e,n){var r=n[0];return e[n[1]]=t.searchParams.get(r)||"",e}),{})}},S={launchEventParams:y({vk_are_notifications_enabled:"maane",vk_is_app_user:"maiau",vk_is_favorite:"maif",vk_ts:"mats"}),eventProviderParams:y({vk_user_id:"mauid",vk_app_id:"maaid",vk_language:"malang",vk_client:"mac",vk_platform:"map",vk_ref:"maref"})};var H=function(e){return{callBeforeCaptureEventHandlers:function(n,t){e.forEach((function(e){var r;null===(r=e.beforeCaptureEvent)||void 0===r||r.call(e,n,t)}))},callEventPayloadParamsProviders:function(n){return e.reduce((function(e,n){var t;return P(P({},e),(null===(t=n.getEventPayloadParams)||void 0===t?void 0:t.call(n))||{})}),n)},callTransports:function(n,t){e.forEach((function(e){var r;null===(r=e.sendEvent)||void 0===r||r.call(e,n,t)}))},callInitializationHandlers:function(){e.forEach((function(e){var n;return null===(n=e.onInit)||void 0===n?void 0:n.call(e)}))},setEventHandler:function(n){e.forEach((function(e){var t;return null===(t=e.setEventHandler)||void 0===t?void 0:t.call(e,n)}))}}};return function(e){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=H(e),r=function(e,n){t.callBeforeCaptureEventHandlers(e,n),t.callTransports(e,t.callEventPayloadParamsProviders(P({},n)))};return t.setEventHandler(r),t.callInitializationHandlers(),r}((c=r(),l=window.document.referrer,s=S.eventProviderParams(location.href),{setEventHandler:function(e){i=e},getEventPayloadParams:function(){return P({lid:c,ref:l},s)},onInit:function(){var e=S.launchEventParams(location.href);setTimeout((function(){i("launch",P({ifr:(window.self!==window.top).toString()},e)),i("mt_internal_launch")}),0)}}),f(),function(e){var n;return void 0===e&&(e={engagementTrackingIntervalMsec:1e4}),{setEventHandler:function(e){n=e},onInit:function(){setInterval((function(){!1===document.hidden&&n("engage")}),e.engagementTrackingIntervalMsec)}}}(),t(),(n=e.initialScreen,a=null,o=n,{getEventPayloadParams:function(){return{sct:o.screenType,scid:o.screenId||""}},beforeCaptureEvent:function(e,n){"screenChange"===e&&(a=o,o={screenType:n.screenType,screenId:n.screenId},Object.assign(n,{psct:a.screenType,pscid:a.screenId||""}),delete n.screenType,delete n.screenId)}}),function(){var e;function n(n){var t,r,a;e("uncaughtError",{message:n.message,filename:n.filename,lineno:null===(t=n.lineno)||void 0===t?void 0:t.toString(),colno:null===(r=n.colno)||void 0===r?void 0:r.toString(),error:null===(a=n.error)||void 0===a?void 0:a.toString()})}function t(n){e("unhandledRejection",{reason:n.reason})}return{setEventHandler:function(n){e=n},onInit:function(){window.addEventListener("error",n),window.addEventListener("unhandledrejection",t)}}}(),_());var n,a,o,i,c,l,s}}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment