Files
huangguo_landpage/public/landing-sdk-v1.1.0.js
T
2026-09-15 16:25:45 +07:00

2 lines
12 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).LandingSDK=t()}(this,function(){"use strict";if("function"!=typeof Object.keys||"function"!=typeof Date.now||"function"!=typeof Array.isArray){var e=function(){},t=function(){};t.landingPageView=e,t.landingPageClick=e;var n=function(){};if(n.init=e,n.track=t,"undefined"!=typeof globalThis)try{globalThis.LandingSDK=n}catch(e){}else"undefined"!=typeof window&&(window.LandingSDK=n);return n}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}var i,o="_s_token_",a="_d_token_",u="_d_sig_",c="_ping_flag_",d="data-app-id",l="app-id",f="event_id",v=null,p=null,s=null,g=null,y=function(e){var t=e.toString(16);return 1===t.length?"0"+t:t},_=function(){for(var e="",t=0;t<16;t++)e+=y(Math.floor(256*Math.random()));return e},h=function(){if(null!==g)return g;try{return window.localStorage.setItem(c,"1"),window.localStorage.removeItem(c),g=!0,!0}catch(e){return g=!1,!1}},w=function(){if("undefined"==typeof navigator)return"PC";var e=navigator.userAgent||"";return/Android/i.test(e)?"Android":/iPhone|iPad|iPod/i.test(e)?"iOS":"PC"},m=function(e){if(!e)return"";for(var t=e+"device_id_secret_key_v1",n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r),n&=n;return Math.abs(n).toString(16)},b=function(){if("undefined"==typeof document)return"";for(var e=document.getElementsByTagName("script"),t=0;t<e.length;t++){var n=e[t],r=n.getAttribute(d)||n.getAttribute(l);if(r)return r}var i=document.currentScript||e[e.length-1];return i?i.getAttribute(d)||i.getAttribute(l):""},k=function(){try{var e="landing_device_fingerprint",t=h()&&window.localStorage.getItem(e)||"";if(t)return t;var n="undefined"!=typeof navigator?navigator:{},r="undefined"!=typeof screen?screen:{},i="undefined"!=typeof Intl&&Intl.DateTimeFormat&&Intl.DateTimeFormat().resolvedOptions().timeZone||"",o=n.language||"",a=Array.isArray(n.languages)?n.languages.join(","):"",u=r.colorDepth||"",c=r.pixelDepth||"",d=void 0!==r.width&&void 0!==r.height?"".concat(r.width,"x").concat(r.height):"",l=void 0!==r.availWidth&&void 0!==r.availHeight?"".concat(r.availWidth,"x").concat(r.availHeight):"",f="undefined"!=typeof window&&window.devicePixelRatio?window.devicePixelRatio:"",v=n.maxTouchPoints||0,p=n.hardwareConcurrency||"",s=n.deviceMemory||"",g=n.platform||"",y=[n.userAgent||"",g,n.vendor||"",o,a,i,(new Date).getTimezoneOffset(),d,l,u,c,f,v,p,s].join("||"),_="fp_".concat(function(){for(var e=2166136261,t=String((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")||""),n=0;n<t.length;n+=1)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0).toString(16).padStart(8,"0")}(y));return function(t){if(t&&h())try{window.localStorage.setItem(e,t)}catch(e){}}(_),_}catch(e){return""}},S=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=function(){if("undefined"==typeof window)return"";if(h())try{var e=window.localStorage.getItem(a),t=window.localStorage.getItem(u);if(e&&!t){var n=_(),r=m(n);return window.localStorage.setItem(a,n),window.localStorage.setItem(u,r),n}if(e&&t){if(m(e)===t)return e;var i=_(),o=m(i);return window.localStorage.setItem(a,i),window.localStorage.setItem(u,o),i}var c=_(),d=m(c);return window.localStorage.setItem(a,c),window.localStorage.setItem(u,d),c}catch(e){}return s||(s=_()),s}(),n=function(){var e,t,n,r=(t=(e=new Date).getMonth()+1,n=e.getDate(),e.getFullYear()+"-"+(t<10?"0"+t:t)+"-"+(n<10?"0"+n:n));if("undefined"!=typeof window&&h())try{var i=window.localStorage.getItem(o);if(i)try{var a=JSON.parse(i);if(a.date===r&&a.sid)return a.sid}catch(e){}var u=_();return window.localStorage.setItem(o,JSON.stringify({sid:u,date:r})),u}catch(e){}return v&&p===r||(v=_(),p=r),v}(),r="",i="";return{app_id:e.appId||b(),uid:0,channel:e.channel||"",sid:n,client_ts:Math.floor(Date.now()/1e3),device:w(),device_id:e.deviceId||t,user_agent:"undefined"==typeof navigator?"":navigator.userAgent||"",device_brand:r,device_model:i,fp_version:"1.0.0",device_fingerprint:k(),sdk_version:"1.1.0",app_version:""}},A=function(){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")||(window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.hostname+(window.location.port?":"+window.location.port:""));if(!n)return"";var r="/"===n.charAt(n.length-1)?n.slice(0,-1):n,i=e?"/dcserv":"",o=t?"/api/eventTracking/batchReport.json":"/api/eventTracking/report.json";return"".concat(r).concat(i).concat(o)},j=function(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];if(n)for(var r=Object.keys(n),i=0;i<r.length;i++)e[r[i]]=n[r[i]]}return e},I=function(e){for(var t=String(null==e?"":e),n=[],r=0;r<t.length;r+=1){var i=t.charCodeAt(r);if(i<128)n.push(i);else if(i<2048)n.push(192|i>>6,128|63&i);else if(i>=55296&&i<=56319&&r+1<t.length){var o=t.charCodeAt(r+1);if(o>=56320&&o<=57343){var a=o-56320+(i-55296<<10)+65536;n.push(240|a>>18,128|a>>12&63,128|a>>6&63,128|63&a),r+=1}else n.push(224|i>>12,128|i>>6&63,128|63&i)}else n.push(224|i>>12,128|i>>6&63,128|63&i)}var u=8*n.length;for(n.push(128);n.length%64!=56;)n.push(0);for(var c=0;c<8;c+=1)n.push(u>>>8*c&255);for(var d=function(e,t){return e<<t|e>>>32-t},l=function(e,t){return((e>>>0)+(t>>>0)&4294967295)>>>0},f=function(e,t,n,r){return l(l(e,t),l(n,r))},v=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21],p=new Array(64),s=0;s<64;s+=1)p[s]=Math.floor(4294967296*Math.abs(Math.sin(s+1)))>>>0;for(var g=1732584193,y=4023233417,_=2562383102,h=271733878,w=0;w<n.length;w+=64){for(var m=new Array(16),b=0;b<16;b+=1){var k=w+4*b;m[b]=(n[k]|n[k+1]<<8|n[k+2]<<16|n[k+3]<<24)>>>0}for(var S=g,A=y,j=_,I=h,O=0;O<64;O+=1){var P=void 0,T=void 0;O<16?(P=A&j|~A&I,T=O):O<32?(P=I&A|~I&j,T=(5*O+1)%16):O<48?(P=A^j^I,T=(3*O+5)%16):(P=j^(A|~I),T=7*O%16);var q=I;I=j,j=A,A=l(A,d(f(S,P,p[O],m[T]),v[O])),S=q}g=l(g,S),y=l(y,A),_=l(_,j),h=l(h,I)}var x=function(e){for(var t="",n=0;n<4;n+=1)t+=(256+(e>>>8*n&255)).toString(16).slice(1);return t};return""+x(g)+x(y)+x(_)+x(h)},O=function(e){return null===e?"__t:null__":"string"==typeof e?"__t:str__:"+e:"number"==typeof e&&isFinite(e)?"__t:num__:"+String(e):"boolean"==typeof e?"__t:bool__:"+(e?"1":"0"):Array.isArray(e)?"["+e.map(O).join(",")+"]":"object"===r(e)?"{"+Object.keys(e).sort().map(function(t){return t+":"+O(e[t])}).join(",")+"}":"__t:any__:"+String(e)},P=function(e){var t=(e=e||{}).endpoint?e.endpoint:A(e.domain,!0,e.batch)||"",n=function(e){return e=e||{},{sendPayload:function(t,n){if(n){var i,o;if(e.batch?(i=JSON.stringify(t),o="application/json"):(i=function(e){for(var t=Object.keys(e||{}),n=[],i=0;i<t.length;i++){var o=t[i],a=e[o];if(null!=a){var u="object"===r(a)?JSON.stringify(a):String(a);n.push(encodeURIComponent(o)+"="+encodeURIComponent(u))}}return n.join("&")}(t),o="application/x-www-form-urlencoded"),"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon){var a=new Blob([i],{type:o});if(navigator.sendBeacon(n,a))return}try{var u=new XMLHttpRequest;u.open("POST",n,!0),u.timeout=1e4,u.setRequestHeader("Content-Type",o),u.send(i)}catch(e){}}}}}(j({endpoint:t},e));return{track:function(r,i){r=r||{};try{if(!r.event)throw new Error("event 字段必填");var o;if(e.batch){var a=r.event,u=j({},r);delete u.event,r={payload:u,event:a}}var c=function(e,t){var n=S(t),r=j({},n,e);return r.endpointOverride=void 0,r[f]||(r[f]=function(e){var t=e||{},n=Object.keys(t).filter(function(e){return e!==f&&"client_ts"!==e}).sort();if(!n.length)return I("");var r=n.map(function(e){return I(O(t[e]))}).join("");return I(r)}(r)),r}(j({},r),j({},e));if(!c.app_id)throw new Error("app_id 字段必填");if(void 0===e.channel||null===e.channel)throw new Error("channel 字段必填");o=e.batch?[c]:c;var d=i||(e.batch?A(e.domain,!0,!0):t);n.sendPayload(o,d)}catch(e){}}}},T={landingPageView:{landing_page_id:{type:"string",required:!0}},landingPageClick:{landing_page_id:{type:"string",required:!0},tab_key:{type:"string",required:!1},tab_name:{type:"string",required:!1},click_coordinates_x:{type:"int",required:!0},click_coordinates_y:{type:"int",required:!0},click_x_percent:{type:"int",required:!0},click_y_percent:{type:"int",required:!0},screen_width:{type:"int",required:!0},screen_height:{type:"int",required:!0},trace_id:{type:"string",required:!0}}},q={event_type:{click:!0,close:!0,show:!0},recommend_content_type:{video:!0,novel:!0,comic:!0},video_content_type:{video:!0,short_video:!0},video_behavior_key:{video_view:!0,video_play:!0,video_pause:!0,video_share:!0,video_complete:!0,video_forward:!0,video_rewind:!0}},x={ad_id:!0,creative_id:!0,recommend_id:!0,novel_tag_key:!0,comic_tag_key:!0,video_tag_key:!0},C=function(e){return String(null==e?"":e).trim()},D=function(e){return"number"==typeof e&&e%1==0},M=function(e){return D(e)?e:"string"==typeof e&&/^[+-]?\d+$/.test(e.trim())?parseInt(e.trim(),10):NaN},E=function(e,t,n,r){if(n)throw new TypeError("[sdk][event] "+e+"."+t+" "+r);return{keep:!1}},$=function(e,t,n,r){if(function(e){return/(^|_)(time|ts|timestamp)$/.test(e)}(t)){var i=M(n);return D(i)&&10===String(Math.abs(i)).length?{keep:!0,value:i}:E(e,t,r,"must be 10-digit int")}if(function(e){return/(^|_)(progress|percent)$/.test(e)}(t)){var o=M(n);return!D(o)||o<0||o>100?E(e,t,r,"must be int in [0,100]"):{keep:!0,value:o}}if(function(e){return"page_no"===e||"click_position"===e||/_position$/.test(e)}(t)){var a=M(n);return!D(a)||a<1?E(e,t,r,"must be int >= 1"):{keep:!0,value:a}}if("amount"===t||"coin_quantity"===t||"search_result_count"===t||"click_page_x"===t||"click_page_y"===t||"screen_width"===t||"screen_height"===t||"video_duration"===t||"play_duration"===t||"page_load_time"===t){var u=M(n);return!D(u)||u<=0?E(e,t,r,"must be int > 0"):{keep:!0,value:u}}if(x[t]){var c=C(n);if(!c)return E(e,t,r,"must not be empty");var d=c.split(",").map(function(e){return e.trim()}).filter(Boolean).join(",");return d?{keep:!0,value:d}:E(e,t,r,"must not be empty")}if(function(e){return/_key$/.test(e)}(t)){var l=C(n);return!l||l.length>64||!/^[A-Za-z0-9_]+$/.test(l)?E(e,t,r,"must match key rule"):{keep:!0,value:l}}if(function(e){return/_name$/.test(e)}(t)){var f=C(n);return f?{keep:!0,value:f.slice(0,128)}:E(e,t,r,"must not be empty")}if(function(e){return/(^id$|_id$)/.test(e)}(t)){var v=C(n);return v?{keep:!0,value:v.slice(0,128)}:E(e,t,r,"must not be empty")}if(function(e){return"comment_content"===e||"keyword"===e||/_title$/.test(e)||"novel_title"===e||"video_title"===e}(t)){var p=C(n),s="comment_content"===t||"keyword"===t?500:256;return p?{keep:!0,value:p.slice(0,s)}:E(e,t,r,"must not be empty")}if(Object.prototype.hasOwnProperty.call(q,t)){var g=C(n);return q[t][g]?{keep:!0,value:g}:E(e,t,r,"must be in enum whitelist")}return"string"==typeof n?{keep:!0,value:n.trim()}:{keep:!0,value:n}},N=function(e){return null===e?"null":Array.isArray(e)?"array":r(e)},R=function(e,t,n){t=t||{};var i=(n=n||{}).allowExtra,o=void 0!==i&&i,a=t&&"object"===r(t)&&!Array.isArray(t)?t:null;if(!a)throw new TypeError("[sdk][event] "+e+" payload must be an object");for(var u=T[e]||{},c=Object.keys(a),d={},l=0;l<c.length;l+=1){var f=c[l],v=u[f];if(!v){if(o){d[f]=a[f];continue}throw new TypeError("[sdk][event] "+e+"."+f+" is not allowed")}var p=$(e,f,a[f],!!v.required);if(p.keep){var s=N(p.value);if(v.type&&!("int"===v.type?"number"===s&&D(p.value):s===v.type))throw new TypeError("[sdk][event] "+e+"."+f+" expected "+v.type+", got "+s);d[f]=p.value}}for(var g=Object.keys(u),y=0;y<g.length;y+=1){var _=g[y];if(u[_].required&&!Object.prototype.hasOwnProperty.call(d,_))throw new TypeError("[sdk][event] "+e+"."+_+" is required")}return j({},d)},L={landingPageView:function(e,t){return j({event:"landing_page_view"},R("landingPageView",e||{},t||{}))},landingPageClick:function(e,t){return j({event:"landing_page_click"},R("landingPageClick",e||{},t||{}))}},B=null,K=function(e,t){return(B||(B=P()),B).track(e,t)};return K.track=function(e,t){return K(e,t)},i=K,Object.keys(L).forEach(function(e){var t=L[e];i.track[e]=function(e,n){try{return i.track(t(e),n)}catch(e){}}}),K.init=function(e){try{B=P(e||{})}catch(e){}},"undefined"!=typeof globalThis?globalThis.LandingSDK=K:"undefined"!=typeof window&&(window.LandingSDK=K),K});