@seaverse/track-sdk 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,7 +33,7 @@ const trackClient = new TrackClient({
33
33
  version: '1.0.0',
34
34
  });
35
35
 
36
- // 初始化
36
+ // 初始化(如果平台配置包含 GTM ID,会自动注入)
37
37
  await trackClient.initialize();
38
38
 
39
39
  // 手动埋点
@@ -123,6 +123,16 @@ const providers = trackClient.getInitializedProviders();
123
123
  console.log(providers); // 已初始化的埋点平台列表
124
124
  ```
125
125
 
126
+ ##### `trackGTMEvent(eventName: string, parameters?: Record<string, any>): void`
127
+
128
+ 追踪 GTM 自定义事件(仅 web 平台有效)。
129
+
130
+ ```typescript
131
+ trackClient.trackGTMEvent('log_login_accounts', {
132
+ loginType: 'seaart-auth',
133
+ });
134
+ ```
135
+
126
136
  ## 使用示例
127
137
 
128
138
  ### React 应用
@@ -160,6 +170,14 @@ function App() {
160
170
  });
161
171
  };
162
172
 
173
+ const handleCustomGTMEvent = () => {
174
+ // 追踪 GTM 自定义事件
175
+ trackClient.trackGTMEvent('custom_button_click', {
176
+ button_id: 'cta_button',
177
+ page_name: 'home',
178
+ });
179
+ };
180
+
163
181
  return <div>Your App</div>;
164
182
  }
165
183
 
@@ -279,6 +297,37 @@ const trackClient = new TrackClient({
279
297
  });
280
298
  ```
281
299
 
300
+ **Q: Google Tag Manager 会自动注入吗?**
301
+
302
+ 是的,如果平台配置中包含 `gtmId`,SDK 会在 Firebase 初始化时自动注入 GTM 代码:
303
+ - 自动在 `<head>` 中插入 GTM script
304
+ - 自动在 `<body>` 最前面插入 noscript fallback
305
+ - 支持重复调用检测,避免重复注入
306
+
307
+ GTM ID 在 `src/config.ts` 的平台配置中设置,无需用户手动传入。
308
+
309
+ **Q: 如何追踪 GTM 自定义事件?**
310
+
311
+ 使用 `trackGTMEvent` 方法:
312
+
313
+ ```typescript
314
+ // 追踪登录事件
315
+ trackClient.trackGTMEvent('log_login_accounts', {
316
+ loginType: 'seaart-auth',
317
+ });
318
+
319
+ // 追踪按钮点击
320
+ trackClient.trackGTMEvent('custom_button_click', {
321
+ button_id: 'purchase_btn',
322
+ page: 'product_detail',
323
+ });
324
+ ```
325
+
326
+ 注意:
327
+ - 该方法仅在 web 平台有效,非 web 平台会输出日志但不执行
328
+ - 事件会推送到 GTM dataLayer,可在 GTM 后台配置触发器和标签
329
+ - 事件名称必须是有效的字符串
330
+
282
331
  ## License
283
332
 
284
333
  MIT
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("firebase/app"),s=require("firebase/analytics");function r(t){var s=Object.create(null);return t&&Object.keys(t).forEach(function(r){if("default"!==r){var e=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(s,r,e.get?e:{enumerable:!0,get:function(){return t[r]}})}}),s.default=t,Object.freeze(s)}var e,n,i=r(require("sa-sdk-javascript"));function o(t,s){return t-=371,a()[t]}function a(){var t=["sensors","297tDQJxZ","163487LncWyn","1684045buxUfK","2428320IZTMRJ","2371179ljcPSQ","4vqhmKv","22YGBMeo","455odrInS","149958gkQzQA","6bTtEDm","SENSORS","firebase","6024496gXXvna","305710CCPtqR"];return(a=function(){return t})()}!function(){for(var t=o,s=a();;)try{if(829439===-parseInt(t(374))/1*(parseInt(t(382))/2)+-parseInt(t(377))/3+parseInt(t(378))/4*(parseInt(t(375))/5)+parseInt(t(381))/6*(parseInt(t(380))/7)+parseInt(t(385))/8+parseInt(t(373))/9*(-parseInt(t(371))/10)+-parseInt(t(379))/11*(-parseInt(t(376))/12))break;s.push(s.shift())}catch(t){s.push(s.shift())}}(),exports.TrackProvider=void 0,e=exports.TrackProvider||(exports.TrackProvider={}),n=o,e.FIREBASE=n(384),e[n(383)]=n(372);const c=l;function l(t,s){t-=112;return p()[t]}function p(){const t=["analytics","track","70EJcNND","108nQVMhI","firebase initialize failed:","error","setUserProperties","8424VnTBHs","setUserId","1687wrwdEo","154vPHpGa","631558cnPISb","initialized","2554428KKZBIe","config","20175AspqHN","306945kDtkwJ","610ZdiTle","7401vVaVdR","192996MJPuKB","clearUserId"];return(p=function(){return t})()}!function(){const t=l,s=p();for(;;)try{if(445436===-parseInt(t(117))/1+parseInt(t(123))/2*(parseInt(t(124))/3)+-parseInt(t(130))/4*(-parseInt(t(121))/5)+parseInt(t(119))/6+parseInt(t(115))/7*(parseInt(t(113))/8)+-parseInt(t(122))/9*(parseInt(t(129))/10)+-parseInt(t(116))/11*(parseInt(t(125))/12))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class f{constructor(t){const s=l;this.analytics=null,this[s(118)]=!1,this[s(120)]=t}async initialize(){const r=l;if(!this[r(118)])try{const e=t.initializeApp(this[r(120)]);this[r(127)]=s.getAnalytics(e),this[r(118)]=!0}catch(t){throw console[r(132)](r(131),t),t}}async[c(128)](t,s){}async[c(114)](t){}async[c(112)](t){}async[c(126)](){}}function h(t,s){t-=255;return d()[t]}const I=h;function d(){const t=["login","warn","4205148LagySc","quick","ajax","?t=","token","setUserProperties","sensors sdk init failed:","10000HGUIKT","36376dxXjRM","sensors sdk not initialized, skip setUserProperties","1395nYjOqU","2158800zPZZZU","serverUrl","setUserId","autoTrack","sensors sdk not initialized, skip setUserId","initialized","sensors sdk not found, please install it by running","sensors sdk track failed:","platform","sensors sdk setUserProperties failed:","1924gzmytc","showLog","10NtlfOT","sensors sdk clearUserId failed:","error","config","2558456mtgsyU","initialize","23677291PEKAMT","heatmap","93GLlCYA","&p=","&v=","version","5FnRYrA","sensors sdk not initialized, skip track","sensors sdk setUserId failed:","track","init","clearUserId","sensors"];return(d=function(){return t})()}!function(){const t=h,s=d();for(;;)try{if(455446===parseInt(t(271))/1+parseInt(t(285))/2*(parseInt(t(295))/3)+-parseInt(t(291))/4*(parseInt(t(255))/5)+-parseInt(t(264))/6+parseInt(t(275))/7+-parseInt(t(272))/8*(parseInt(t(274))/9)+-parseInt(t(287))/10*(-parseInt(t(293))/11))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class u{constructor(t,s,r,e){const n=h;this[n(261)]=null,this.initialized=!1,this[n(268)]=t,this[n(283)]=s,this[n(298)]=r,this[n(290)]=e}async[I(292)](){const t=I;if(!this[t(280)])try{if(!i)throw new Error(t(281));this[t(261)]=i;const s=encodeURIComponent(this[t(268)]),r=encodeURIComponent(this[t(283)]),e=encodeURIComponent(this[t(298)]);this[t(261)][t(259)]({server_url:this.config[t(276)]+(t(267)+s+t(296)+r+t(297)+e),show_log:this[t(290)][t(286)]??!1,heatmap:this[t(290)][t(294)]??{},is_track_single_page:!0,send_type:t(266)}),this[t(280)]=!0,this[t(261)][t(265)](t(278))}catch(s){throw console.error(t(270),s),s}}async[I(258)](t,s){const r=I;if(this[r(280)]&&this[r(261)])try{this[r(261)][r(258)](t,s??{})}catch(t){console[r(289)](r(282),t)}else console[r(263)](r(256))}async[I(277)](t){const s=I;if(this.initialized&&this[s(261)])try{this[s(261)][s(262)](t)}catch(t){console.error(s(257),t)}else console[s(263)](s(279))}async[I(269)](t){const s=I;if(this.initialized&&this[s(261)])try{this[s(261)].setProfile(t)}catch(t){console[s(289)](s(284),t)}else console[s(263)](s(273))}async[I(260)](){const t=I;if(this[t(280)]&&this[t(261)])try{this[t(261)].logout()}catch(s){console.error(t(288),s)}}}function k(){var t=["atob","3260qrbkko","from","14772ApEzQO","undefined","toString","base64","72575yVezWQ","1kfKYQU","utf-8","10EsMsFG","204VZMywi","3182553ClSoya","111377HkznwU","456970poanGf","1899MkhrjZ","1706023vNkSru","8WqMktq","btoa","169eJFqyd"];return(k=function(){return t})()}function y(t,s){return t-=445,k()[t]}function w(t){var s=y;return typeof window!==s(455)&&window[s(449)]?window[s(449)](t):Buffer[s(453)](t,s(460))[s(456)](s(457))}function z(t){return JSON.parse((s=t,r=y,typeof window!==r(455)&&window[r(451)]?window[r(451)](s):Buffer[r(453)](s,r(457))[r(456)](r(460))));var s,r}!function(){for(var t=y,s=k();;)try{if(285664===parseInt(t(459))/1*(-parseInt(t(445))/2)+-parseInt(t(446))/3*(-parseInt(t(452))/4)+parseInt(t(458))/5+parseInt(t(462))/6*(-parseInt(t(464))/7)+parseInt(t(448))/8*(parseInt(t(463))/9)+-parseInt(t(461))/10*(-parseInt(t(447))/11)+parseInt(t(454))/12*(parseInt(t(450))/13))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const Z=m;!function(){const t=m,s=b();for(;;)try{if(354492===parseInt(t(157))/1*(parseInt(t(146))/2)+parseInt(t(149))/3+parseInt(t(145))/4+-parseInt(t(156))/5*(-parseInt(t(151))/6)+-parseInt(t(144))/7+parseInt(t(148))/8+-parseInt(t(154))/9)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const v={"MDE5YjUzNTEyMWJhNzc1ZmIwYTQ1MzY3Njg1NzU1MTU=":{providers:[exports.TrackProvider[Z(152)],exports.TrackProvider.SENSORS],firebaseConfig:z(Z(147)),sensorsConfig:z("eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19")},"MDE5YjUzNTE3ZmFiN2YxZDkwNjg5OWVhMGQyMWJlZGI=":{providers:[exports.TrackProvider[Z(152)],exports.TrackProvider[Z(153)]],firebaseConfig:z(Z(155)),sensorsConfig:z(Z(150))}};function m(t,s){t-=144;return b()[t]}function b(){const t=["85461vrkAAK","eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19","880494KCWboB","FIREBASE","SENSORS","6572673qrVjNM","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjpkMTQ4OGM3MzI0MWIyZWMzNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctR0gxNk1CQ1NOVyJ9","5TmlrZV","1knsfWw","3777865WWsdvf","1109532ptFHPd","1012358WAdnsG","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjo2NmI2ZTNmNmEwZjM2MDkwNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctN0gySjFTQ05QRCJ9","5325488pMKcVU"];return(b=function(){return t})()}const M=W;function W(t,s){t-=459;return g()[t]}function g(){const t=["values","config","Must provide a token","validateConfig"," adapter failed:","platform","[Track] Skip Firebase initialization (initializeFirebase = false)","providers","allSettled","clearUserId","FIREBASE","setUserId","605088WNrEsP","token","384yKwtET","[Track] ","32158fpmMNA","492UzBrao","setUserProperties","push","Must provide a version","61839MtUIkY","track SDK not initialized, please call initialize() first","Invalid token: ","[Track] Clear User ID","platformConfig","673916xMBCMM","83515TDlSkK","debug","initialized","set","warn","keys","420088DNJbVq","initialize","log","getInitializedProviders","initialize ","6081gtfkRB","initializeFirebase","70ZxbMFS","Must provide a platform","[Track] Set User Properties:","version","adapters","error","track"];return(g=function(){return t})()}!function(){const t=W,s=g();for(;;)try{if(219969===parseInt(t(479))/1+-parseInt(t(472))/2+parseInt(t(484))/3*(-parseInt(t(463))/4)+parseInt(t(473))/5+parseInt(t(505))/6+-parseInt(t(462))/7*(-parseInt(t(460))/8)+-parseInt(t(467))/9*(-parseInt(t(486))/10))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class TrackClient{constructor(t){const s=W;this[s(490)]=new Map,this[s(475)]=!1,this[s(494)]=t,this[s(496)](),this.platformConfig=function(t){const s=w(t),r=v[s];if(!r)throw new Error("invalid token: "+t);return r}(t.token)}validateConfig(){const t=W;if(!this[t(494)][t(459)])throw new Error(t(495));if(!this.config[t(498)])throw new Error(t(487));if(!this.config[t(489)])throw new Error(t(466));if(!(w(this[t(494)][t(459)])in v))throw new Error(t(469)+this[t(494)][t(459)])}async[M(480)](){const t=M;if(this[t(475)])return;const s=[],r=!1!==this[t(494)][t(485)];for(const e of this[t(471)][t(500)])try{if(e===exports.TrackProvider[t(503)]&&!r){this[t(494)][t(474)]&&console.log(t(499));continue}let n;switch(e){case exports.TrackProvider[t(503)]:n=new f(this[t(471)].firebaseConfig);break;case exports.TrackProvider.SENSORS:n=new u(this[t(494)][t(459)],this[t(494)].platform,this[t(494)][t(489)],this[t(471)].sensorsConfig);break;default:console.warn("unknown provider: "+e);continue}this[t(490)][t(476)](e,n),s[t(465)](n.initialize())}catch(s){console[t(491)](t(483)+e+t(497),s)}await Promise.allSettled(s),this[t(475)]=!0,this[t(494)].debug&&console[t(481)]("Track SDK initialized, enabled providers:",Array.from(this[t(490)].keys()))}async[M(492)](t,s){const r=M;if(!this[r(475)])return void console[r(477)](r(468));this[r(494)][r(474)]&&console.log(r(461)+t,s);const e=[];for(const n of this.adapters[r(493)]())e[r(465)](n[r(492)](t,s));await Promise.allSettled(e)}async[M(504)](t){const s=M;if(!this[s(475)])return void console.warn(s(468));this.config[s(474)]&&console[s(481)]("[Track] Set User ID:",t);const r=[];for(const e of this[s(490)].values())r[s(465)](e.setUserId(t));await Promise[s(501)](r)}async[M(464)](t){const s=M;if(!this[s(475)])return void console[s(477)](s(468));this[s(494)][s(474)]&&console.log(s(488),t);const r=[];for(const e of this[s(490)][s(493)]())r[s(465)](e[s(464)](t));await Promise[s(501)](r)}async[M(502)](){const t=M;if(!this[t(475)])return void console[t(477)](t(468));this.config[t(474)]&&console.log(t(470));const s=[];for(const r of this[t(490)].values())s.push(r[t(502)]());await Promise[t(501)](s)}[M(482)](){const t=M;return Array.from(this[t(490)][t(478)]())}}function J(){var t=["32SgbGKg","13277sDXSua","6010DhxHtX","783710XdSXHe","97871pbrJYC","242604lBScki","30678fUxqQA","316cJoVjP","1766924BGaTQl","501bLqUoP","532ArrsRj"];return(J=function(){return t})()}function N(t,s){return t-=409,J()[t]}!function(){for(var t=N,s=J();;)try{if(225315===parseInt(t(416))/1+-parseInt(t(419))/2*(parseInt(t(410))/3)+parseInt(t(409))/4+parseInt(t(415))/5+-parseInt(t(418))/6*(-parseInt(t(411))/7)+-parseInt(t(412))/8*(parseInt(t(417))/9)+parseInt(t(414))/10*(-parseInt(t(413))/11))break;s.push(s.shift())}catch(t){s.push(s.shift())}}(),exports.TrackClient=TrackClient;
1
+ "use strict";var t=require("firebase/app"),e=require("firebase/analytics");function s(t){var e=Object.create(null);return t&&Object.keys(t).forEach(function(s){if("default"!==s){var n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:function(){return t[s]}})}}),e.default=t,Object.freeze(e)}var n,r=s(require("sa-sdk-javascript"));function i(t,e){return t-=430,o()[t]}function o(){var t=["12glWDsv","FIREBASE","2001590tQDYCx","819981fHKBSZ","91862EZzuxl","1985224OWTheH","1OEGyTL","14mZUTpM","1197891rdCOBi","418630aTPpkc","765344vvtCBA"];return(o=function(){return t})()}function a(){const t=["https://www.googletagmanager.com/ns.html?id=","warn","4xbjJJX","height","[GoogleTagManager] Pushed to dataLayer:","gtm.js?id=","[GoogleTagManager] Error pushing to dataLayer:","style","head","[GTM] Already injected, skip","string","parentNode","push","dataLayer","3632CIaSpN","1205405xJWWIc","21140KuVZpu","from","[GTM] Not in browser environment, skip injection","appendChild","body","[GoogleTagManager] Invalid event name:","firstChild","424IAhoXb","width","some","script","visibility","244473xnDKEm","[GTM] Injection failed:","noscript","src","[GoogleTagManager] dataLayer not initialized","none","log","76GDmEdj","iframe","createElement","includes","126720BJWxam","display","async","1582461jKHBqD","insertBefore","error","2364774HORbGx","querySelectorAll","undefined","https://www.googletagmanager.com/gtm.js?id="];return(a=function(){return t})()}function c(){const t=d;return typeof window!==t(270)&&typeof document!==t(270)}function d(t,e){t-=233;return a()[t]}function l(t){const e=d,s=document[e(260)](e(253)),n=document[e(260)](e(259));n[e(254)]=e(272)+t,n[e(275)]="0",n[e(247)]="0",n[e(279)][e(263)]=e(256),n[e(279)][e(250)]="hidden",s[e(242)](n),document[e(243)].firstChild?document.body[e(266)](s,document.body[e(245)]):document[e(243)].appendChild(s)}function p(t,e=!1){const s=d;if(c())if(t)if(function(t){const e=d;if(!c())return!1;const s=!!window[e(236)],n=document[e(269)](e(249)),r=Array[e(240)](n)[e(248)](s=>s.src[e(261)](e(277)+t));return s&&r}(t))e&&console.log(s(281));else try{(function(t){const e=d;window[e(236)]=window[e(236)]||[],window.dataLayer[e(235)]({"gtm.start":(new Date).getTime(),event:"gtm.js"});const s=document[e(260)](e(249));s[e(264)]=!0,s[e(254)]=e(271)+t;const n=document.getElementsByTagName(e(249))[0];n&&n.parentNode?n[e(234)][e(266)](s,n):document[e(280)][e(242)](s)})(t),document[s(243)]?l(t):document.addEventListener("DOMContentLoaded",()=>{l(t)}),e&&console[s(257)]("[GTM] Injected successfully: "+t)}catch(t){console.error(s(252),t)}else e&&console[s(273)]("[GTM] GTM ID is empty, skip injection");else e&&console.warn(s(241))}!function(){for(var t=i,e=o();;)try{if(324898===-parseInt(t(440))/1*(parseInt(t(438))/2)+parseInt(t(431))/3+-parseInt(t(439))/4+-parseInt(t(432))/5*(-parseInt(t(434))/6)+parseInt(t(430))/7*(parseInt(t(433))/8)+-parseInt(t(437))/9+parseInt(t(436))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}(),exports.TrackProvider=void 0,(n=exports.TrackProvider||(exports.TrackProvider={}))[i(435)]="firebase",n.SENSORS="sensors",function(){const t=d,e=a();for(;;)try{if(230124===-parseInt(t(237))/1*(parseInt(t(258))/2)+-parseInt(t(251))/3*(-parseInt(t(274))/4)+parseInt(t(238))/5+parseInt(t(268))/6+-parseInt(t(239))/7*(parseInt(t(246))/8)+-parseInt(t(265))/9+-parseInt(t(262))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const h=(t,e)=>{const s=d;if(!t||typeof t!==s(233))return void console[s(267)](s(244),t);(t=>{const e=d;if(typeof window!==e(270)&&window[e(236)])try{window[e(236)][e(235)](t),console[e(257)](e(276),t)}catch(t){console[e(267)](e(278),t)}else console[e(267)](e(255))})({event:t,...e||{}})};function f(){const t=["analytics","453663omFosI","18003952UYuKDR","setUserProperties","2445528ZmyCvO","track","error","setUserId","initialized","794442kDpdKe","507678TuOpzE","6049392PYPqjo","config","2332420yUpIMI","gtmId","firebase initialize failed:","debug","35bhxuhs"];return(f=function(){return t})()}const u=I;function I(t,e){t-=200;return f()[t]}!function(){const t=I,e=f();for(;;)try{if(788670===-parseInt(t(202))/1+-parseInt(t(205))/2+-parseInt(t(211))/3+parseInt(t(212))/4+-parseInt(t(214))/5+parseInt(t(210))/6*(-parseInt(t(200))/7)+parseInt(t(203))/8)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class m{constructor(t,e,s=!1){const n=I;this[n(201)]=null,this[n(209)]=!1,this[n(213)]=t,this.gtmId=e,this.debug=s}async initialize(){const s=I;if(!this[s(209)])try{this[s(215)]&&p(this.gtmId,this[s(217)]);const n=t.initializeApp(this[s(213)]);this[s(201)]=e.getAnalytics(n),this[s(209)]=!0}catch(t){throw console[s(207)](s(216),t),t}}async[u(206)](t,e){}async[u(208)](t){}async[u(204)](t){}async clearUserId(){}}const y=k;function w(){const t=["setProfile","initialize","4495DSdori","logout","21679875fnXuwx","showLog","4563352xMCRdN","sensors","heatmap","ajax","sensors sdk not initialized, skip track","sensors sdk not initialized, skip setUserProperties","clearUserId","3619504CBhIgy","1292949BCqOLp","900272coWgmd","platform","track","sensors sdk not initialized, skip setUserId","6594RrCyli","?t=","warn","26600mxdgzq","setUserId","token","sensors sdk not found, please install it by running","setUserProperties","init","error","sensors sdk setUserProperties failed:","config","sensors sdk init failed:","sensors sdk setUserId failed:","84SlKwzo","sensors sdk track failed:","initialized","&v="];return(w=function(){return t})()}function k(t,e){t-=491;return w()[t]}!function(){const t=k,e=w();for(;;)try{if(577902===-parseInt(t(503))/1*(-parseInt(t(514))/2)+-parseInt(t(495))/3+parseInt(t(496))/4+parseInt(t(520))/5*(parseInt(t(500))/6)+parseInt(t(494))/7+parseInt(t(524))/8+-parseInt(t(522))/9)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class g{constructor(t,e,s,n){const r=k;this[r(525)]=null,this[r(516)]=!1,this[r(505)]=t,this[r(497)]=e,this.version=s,this[r(511)]=n}async[y(519)](){const t=y;if(!this[t(516)])try{if(!r)throw new Error(t(506));this[t(525)]=r;const e=encodeURIComponent(this[t(505)]),s=encodeURIComponent(this[t(497)]),n=encodeURIComponent(this.version);this[t(525)][t(508)]({server_url:this[t(511)].serverUrl+(t(501)+e+"&p=")+s+t(517)+n,show_log:this[t(511)][t(523)]??!1,heatmap:this[t(511)][t(526)]??{},is_track_single_page:!0,send_type:t(527)}),this[t(516)]=!0,this.sensors.quick("autoTrack")}catch(e){throw console[t(509)](t(512),e),e}}async[y(498)](t,e){const s=y;if(this[s(516)]&&this[s(525)])try{this[s(525)][s(498)](t,e??{})}catch(t){console.error(s(515),t)}else console[s(502)](s(491))}async[y(504)](t){const e=y;if(this[e(516)]&&this[e(525)])try{this[e(525)].login(t)}catch(t){console.error(e(513),t)}else console.warn(e(499))}async[y(507)](t){const e=y;if(this[e(516)]&&this.sensors)try{this.sensors[e(518)](t)}catch(t){console.error(e(510),t)}else console[e(502)](e(492))}async[y(493)](){const t=y;if(this[t(516)]&&this.sensors)try{this[t(525)][t(521)]()}catch(e){console[t(509)]("sensors sdk clearUserId failed:",e)}}}function v(){var t=["6868253TXhhuJ","undefined","2506398PcueeQ","btoa","base64","78Rfmzmi","2261528ZmKvmc","toString","utf-8","1128filLbp","11036870JPqymD","15oVqSsu","atob","823668vZiTtf","14913yXtXDF","17939jbHTYV"];return(v=function(){return t})()}function b(t,e){return t-=261,v()[t]}function z(t){var e=b;return"undefined"!=typeof window&&window[e(261)]?window[e(261)](t):Buffer.from(t,e(266))[e(265)]("base64")}function Z(t){return JSON.parse((e=t,s=b,typeof window!==s(275)&&window.atob?window[s(270)](e):Buffer.from(e,s(262)).toString(s(266))));var e,s}!function(){for(var t=b,e=v();;)try{if(642505===parseInt(t(273))/1*(parseInt(t(263))/2)+parseInt(t(271))/3+parseInt(t(264))/4+parseInt(t(269))/5*(-parseInt(t(276))/6)+-parseInt(t(274))/7+parseInt(t(267))/8*(parseInt(t(272))/9)+parseInt(t(268))/10)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const T=N;!function(){const t=N,e=W();for(;;)try{if(359557===-parseInt(t(173))/1*(parseInt(t(175))/2)+parseInt(t(172))/3+-parseInt(t(165))/4*(-parseInt(t(171))/5)+-parseInt(t(161))/6+parseInt(t(170))/7+parseInt(t(164))/8+-parseInt(t(166))/9*(-parseInt(t(163))/10))break;e.push(e.shift())}catch(t){e.push(e.shift())}}();const M={"MDE5YjUzNTEyMWJhNzc1ZmIwYTQ1MzY3Njg1NzU1MTU=":{providers:[exports.TrackProvider.FIREBASE,exports.TrackProvider.SENSORS],firebaseConfig:Z(T(162)),sensorsConfig:Z(T(176)),gtmId:T(169)},"MDE5YjUzNTE3ZmFiN2YxZDkwNjg5OWVhMGQyMWJlZGI=":{providers:[exports.TrackProvider[T(174)],exports.TrackProvider.SENSORS],firebaseConfig:Z(T(168)),sensorsConfig:Z("eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19")}};function W(){const t=["8840ebUioO","466232VocMFV","8GBTfbx","9VfVDQN","invalid token: ","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjpkMTQ4OGM3MzI0MWIyZWMzNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctR0gxNk1CQ1NOVyJ9","GTM-MJDRW2W4","3985310KDTNbZ","402455mGOINX","1727022HgsBAD","2bLBHIk","FIREBASE","561186kqojIS","eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19","2666436CUieRQ","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjo2NmI2ZTNmNmEwZjM2MDkwNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctN0gySjFTQ05QRCJ9"];return(W=function(){return t})()}function N(t,e){t-=161;return W()[t]}const J=S;function S(t,e){t-=384;return C()[t]}function C(){const t=["Must provide a token","1105356abWdOV","keys","providers","token","15sCKKDt","132036ddNKyX","253aKLiKm","[Track] Clear User ID","trackGTMEvent","warn","allSettled","[Track] Set User ID:","4057713AafXPB","Must provide a platform","Track SDK initialized, enabled providers:","unknown provider: ","adapters","config","debug","15319vFlWyN","setUserId","log","8nghjzf","17610905LVahoh","set","firebaseConfig","initialized","10KLEqge","track SDK not initialized, please call initialize() first","70XhMhPV","initialize","[Track] Set User Properties:","initialize ","clearUserId","version","platformConfig","FIREBASE","validateConfig","track","from","getInitializedProviders","push","554444JFFIWm","setUserProperties","5789wyxboT","platform","error","Invalid token: ","values","10jyWoWP"];return(C=function(){return t})()}!function(){const t=S,e=C();for(;;)try{if(461766===parseInt(t(414))/1*(-parseInt(t(424))/2)+parseInt(t(399))/3*(-parseInt(t(386))/4)+-parseInt(t(422))/5*(parseInt(t(395))/6)+parseInt(t(388))/7*(parseInt(t(417))/8)+-parseInt(t(407))/9*(-parseInt(t(393))/10)+-parseInt(t(401))/11*(-parseInt(t(400))/12)+parseInt(t(418))/13)break;e.push(e.shift())}catch(t){e.push(e.shift())}}();class TrackClient{constructor(t){const e=S;this[e(411)]=new Map,this[e(421)]=!1,this.config=t,this[e(432)](),this[e(430)]=function(t){const e=T,s=z(t),n=M[s];if(!n)throw new Error(e(167)+t);return n}(t[e(398)])}[J(432)](){const t=J;if(!this[t(412)].token)throw new Error(t(394));if(!this[t(412)].platform)throw new Error(t(408));if(!this[t(412)][t(429)])throw new Error("Must provide a version");if(!(z(this[t(412)].token)in M))throw new Error(t(391)+this[t(412)][t(398)])}async initialize(){const t=J;if(this[t(421)])return;const e=[],s=!1!==this[t(412)].initializeFirebase;for(const n of this[t(430)][t(397)])try{if(n===exports.TrackProvider[t(431)]&&!s){this.config.debug&&console[t(416)]("[Track] Skip Firebase initialization (initializeFirebase = false)");continue}let r;switch(n){case exports.TrackProvider[t(431)]:r=new m(this[t(430)][t(420)],this[t(430)].gtmId,this[t(412)].debug);break;case exports.TrackProvider.SENSORS:r=new g(this[t(412)][t(398)],this[t(412)][t(389)],this[t(412)][t(429)],this.platformConfig.sensorsConfig);break;default:console.warn(t(410)+n);continue}this[t(411)][t(419)](n,r),e[t(385)](r[t(425)]())}catch(e){console[t(390)](t(427)+n+" adapter failed:",e)}await Promise[t(405)](e),this[t(421)]=!0,this[t(412)][t(413)]&&console.log(t(409),Array[t(434)](this[t(411)].keys()))}async track(t,e){const s=J;if(!this.initialized)return void console[s(404)](s(423));this[s(412)][s(413)]&&console[s(416)]("[Track] "+t,e);const n=[];for(const r of this[s(411)].values())n[s(385)](r[s(433)](t,e));await Promise[s(405)](n)}async[J(415)](t){const e=J;if(!this.initialized)return void console.warn(e(423));this[e(412)].debug&&console.log(e(406),t);const s=[];for(const n of this[e(411)][e(392)]())s[e(385)](n[e(415)](t));await Promise.allSettled(s)}async setUserProperties(t){const e=J;if(!this.initialized)return void console[e(404)](e(423));this[e(412)][e(413)]&&console[e(416)](e(426),t);const s=[];for(const n of this[e(411)][e(392)]())s[e(385)](n[e(387)](t));await Promise[e(405)](s)}async[J(428)](){const t=J;if(!this[t(421)])return void console[t(404)](t(423));this.config[t(413)]&&console[t(416)](t(402));const e=[];for(const s of this[t(411)][t(392)]())e.push(s[t(428)]());await Promise[t(405)](e)}[J(384)](){const t=J;return Array[t(434)](this.adapters[t(396)]())}[J(403)](t,e){h(t,e)}}function j(t,e){return t-=484,F()[t]}function F(){var t=["500234qOoZBl","2964096smBwTo","38520QCxcbo","72Idntpy","823JmCXqa","1626819UNLiSY","576FFWSdF","2715860VimdSk","760FUqSYE","1043312OysbDu"];return(F=function(){return t})()}!function(){for(var t=j,e=F();;)try{if(350169===parseInt(t(487))/1*(parseInt(t(491))/2)+-parseInt(t(488))/3+-parseInt(t(492))/4+-parseInt(t(490))/5+parseInt(t(484))/6+parseInt(t(493))/7*(parseInt(t(486))/8)+parseInt(t(489))/9*(parseInt(t(485))/10))break;e.push(e.shift())}catch(t){e.push(e.shift())}}(),exports.TrackClient=TrackClient;
package/dist/index.d.ts CHANGED
@@ -37,6 +37,11 @@ interface TrackConfig {
37
37
  * 是否初始化 Firebase(默认 true)
38
38
  */
39
39
  initializeFirebase?: boolean;
40
+ /**
41
+ * Google Tag Manager ID(如:GTM-XXXXXXX)
42
+ * 如果提供,SDK 会自动注入 GTM 代码到页面
43
+ */
44
+ gtmId?: string;
40
45
  /**
41
46
  * 是否启用调试模式
42
47
  */
@@ -84,6 +89,12 @@ declare class TrackClient {
84
89
  * 获取已初始化的提供商列表
85
90
  */
86
91
  getInitializedProviders(): TrackProvider[];
92
+ /**
93
+ * 追踪 GTM 自定义事件
94
+ * @param eventName 事件名称
95
+ * @param parameters 事件参数
96
+ */
97
+ trackGTMEvent(eventName: string, parameters?: Record<string, any>): void;
87
98
  }
88
99
 
89
100
  export { TrackClient, TrackProvider };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{initializeApp as t}from"firebase/app";import{getAnalytics as s}from"firebase/analytics";import*as n from"sa-sdk-javascript";var i,r,e;function o(t,s){return t-=371,a()[t]}function a(){var t=["sensors","297tDQJxZ","163487LncWyn","1684045buxUfK","2428320IZTMRJ","2371179ljcPSQ","4vqhmKv","22YGBMeo","455odrInS","149958gkQzQA","6bTtEDm","SENSORS","firebase","6024496gXXvna","305710CCPtqR"];return(a=function(){return t})()}!function(){for(var t=o,s=a();;)try{if(829439===-parseInt(t(374))/1*(parseInt(t(382))/2)+-parseInt(t(377))/3+parseInt(t(378))/4*(parseInt(t(375))/5)+parseInt(t(381))/6*(parseInt(t(380))/7)+parseInt(t(385))/8+parseInt(t(373))/9*(-parseInt(t(371))/10)+-parseInt(t(379))/11*(-parseInt(t(376))/12))break;s.push(s.shift())}catch(t){s.push(s.shift())}}(),r=i||(i={}),e=o,r.FIREBASE=e(384),r[e(383)]=e(372);const c=l;function l(t,s){t-=112;return p()[t]}function p(){const t=["analytics","track","70EJcNND","108nQVMhI","firebase initialize failed:","error","setUserProperties","8424VnTBHs","setUserId","1687wrwdEo","154vPHpGa","631558cnPISb","initialized","2554428KKZBIe","config","20175AspqHN","306945kDtkwJ","610ZdiTle","7401vVaVdR","192996MJPuKB","clearUserId"];return(p=function(){return t})()}!function(){const t=l,s=p();for(;;)try{if(445436===-parseInt(t(117))/1+parseInt(t(123))/2*(parseInt(t(124))/3)+-parseInt(t(130))/4*(-parseInt(t(121))/5)+parseInt(t(119))/6+parseInt(t(115))/7*(parseInt(t(113))/8)+-parseInt(t(122))/9*(parseInt(t(129))/10)+-parseInt(t(116))/11*(parseInt(t(125))/12))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class h{constructor(t){const s=l;this.analytics=null,this[s(118)]=!1,this[s(120)]=t}async initialize(){const n=l;if(!this[n(118)])try{const i=t(this[n(120)]);this[n(127)]=s(i),this[n(118)]=!0}catch(t){throw console[n(132)](n(131),t),t}}async[c(128)](t,s){}async[c(114)](t){}async[c(112)](t){}async[c(126)](){}}function f(t,s){t-=255;return d()[t]}const I=f;function d(){const t=["login","warn","4205148LagySc","quick","ajax","?t=","token","setUserProperties","sensors sdk init failed:","10000HGUIKT","36376dxXjRM","sensors sdk not initialized, skip setUserProperties","1395nYjOqU","2158800zPZZZU","serverUrl","setUserId","autoTrack","sensors sdk not initialized, skip setUserId","initialized","sensors sdk not found, please install it by running","sensors sdk track failed:","platform","sensors sdk setUserProperties failed:","1924gzmytc","showLog","10NtlfOT","sensors sdk clearUserId failed:","error","config","2558456mtgsyU","initialize","23677291PEKAMT","heatmap","93GLlCYA","&p=","&v=","version","5FnRYrA","sensors sdk not initialized, skip track","sensors sdk setUserId failed:","track","init","clearUserId","sensors"];return(d=function(){return t})()}!function(){const t=f,s=d();for(;;)try{if(455446===parseInt(t(271))/1+parseInt(t(285))/2*(parseInt(t(295))/3)+-parseInt(t(291))/4*(parseInt(t(255))/5)+-parseInt(t(264))/6+parseInt(t(275))/7+-parseInt(t(272))/8*(parseInt(t(274))/9)+-parseInt(t(287))/10*(-parseInt(t(293))/11))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class u{constructor(t,s,n,i){const r=f;this[r(261)]=null,this.initialized=!1,this[r(268)]=t,this[r(283)]=s,this[r(298)]=n,this[r(290)]=i}async[I(292)](){const t=I;if(!this[t(280)])try{if(!n)throw new Error(t(281));this[t(261)]=n;const s=encodeURIComponent(this[t(268)]),i=encodeURIComponent(this[t(283)]),r=encodeURIComponent(this[t(298)]);this[t(261)][t(259)]({server_url:this.config[t(276)]+(t(267)+s+t(296)+i+t(297)+r),show_log:this[t(290)][t(286)]??!1,heatmap:this[t(290)][t(294)]??{},is_track_single_page:!0,send_type:t(266)}),this[t(280)]=!0,this[t(261)][t(265)](t(278))}catch(s){throw console.error(t(270),s),s}}async[I(258)](t,s){const n=I;if(this[n(280)]&&this[n(261)])try{this[n(261)][n(258)](t,s??{})}catch(t){console[n(289)](n(282),t)}else console[n(263)](n(256))}async[I(277)](t){const s=I;if(this.initialized&&this[s(261)])try{this[s(261)][s(262)](t)}catch(t){console.error(s(257),t)}else console[s(263)](s(279))}async[I(269)](t){const s=I;if(this.initialized&&this[s(261)])try{this[s(261)].setProfile(t)}catch(t){console[s(289)](s(284),t)}else console[s(263)](s(273))}async[I(260)](){const t=I;if(this[t(280)]&&this[t(261)])try{this[t(261)].logout()}catch(s){console.error(t(288),s)}}}function k(){var t=["atob","3260qrbkko","from","14772ApEzQO","undefined","toString","base64","72575yVezWQ","1kfKYQU","utf-8","10EsMsFG","204VZMywi","3182553ClSoya","111377HkznwU","456970poanGf","1899MkhrjZ","1706023vNkSru","8WqMktq","btoa","169eJFqyd"];return(k=function(){return t})()}function y(t,s){return t-=445,k()[t]}function w(t){var s=y;return typeof window!==s(455)&&window[s(449)]?window[s(449)](t):Buffer[s(453)](t,s(460))[s(456)](s(457))}function m(t){return JSON.parse((s=t,n=y,typeof window!==n(455)&&window[n(451)]?window[n(451)](s):Buffer[n(453)](s,n(457))[n(456)](n(460))));var s,n}!function(){for(var t=y,s=k();;)try{if(285664===parseInt(t(459))/1*(-parseInt(t(445))/2)+-parseInt(t(446))/3*(-parseInt(t(452))/4)+parseInt(t(458))/5+parseInt(t(462))/6*(-parseInt(t(464))/7)+parseInt(t(448))/8*(parseInt(t(463))/9)+-parseInt(t(461))/10*(-parseInt(t(447))/11)+parseInt(t(454))/12*(parseInt(t(450))/13))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const Z=M;!function(){const t=M,s=v();for(;;)try{if(354492===parseInt(t(157))/1*(parseInt(t(146))/2)+parseInt(t(149))/3+parseInt(t(145))/4+-parseInt(t(156))/5*(-parseInt(t(151))/6)+-parseInt(t(144))/7+parseInt(t(148))/8+-parseInt(t(154))/9)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const z={"MDE5YjUzNTEyMWJhNzc1ZmIwYTQ1MzY3Njg1NzU1MTU=":{providers:[i[Z(152)],i.SENSORS],firebaseConfig:m(Z(147)),sensorsConfig:m("eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19")},"MDE5YjUzNTE3ZmFiN2YxZDkwNjg5OWVhMGQyMWJlZGI=":{providers:[i[Z(152)],i[Z(153)]],firebaseConfig:m(Z(155)),sensorsConfig:m(Z(150))}};function M(t,s){t-=144;return v()[t]}function v(){const t=["85461vrkAAK","eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19","880494KCWboB","FIREBASE","SENSORS","6572673qrVjNM","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjpkMTQ4OGM3MzI0MWIyZWMzNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctR0gxNk1CQ1NOVyJ9","5TmlrZV","1knsfWw","3777865WWsdvf","1109532ptFHPd","1012358WAdnsG","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjo2NmI2ZTNmNmEwZjM2MDkwNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctN0gySjFTQ05QRCJ9","5325488pMKcVU"];return(v=function(){return t})()}const b=W;function W(t,s){t-=459;return J()[t]}function J(){const t=["values","config","Must provide a token","validateConfig"," adapter failed:","platform","[Track] Skip Firebase initialization (initializeFirebase = false)","providers","allSettled","clearUserId","FIREBASE","setUserId","605088WNrEsP","token","384yKwtET","[Track] ","32158fpmMNA","492UzBrao","setUserProperties","push","Must provide a version","61839MtUIkY","track SDK not initialized, please call initialize() first","Invalid token: ","[Track] Clear User ID","platformConfig","673916xMBCMM","83515TDlSkK","debug","initialized","set","warn","keys","420088DNJbVq","initialize","log","getInitializedProviders","initialize ","6081gtfkRB","initializeFirebase","70ZxbMFS","Must provide a platform","[Track] Set User Properties:","version","adapters","error","track"];return(J=function(){return t})()}!function(){const t=W,s=J();for(;;)try{if(219969===parseInt(t(479))/1+-parseInt(t(472))/2+parseInt(t(484))/3*(-parseInt(t(463))/4)+parseInt(t(473))/5+parseInt(t(505))/6+-parseInt(t(462))/7*(-parseInt(t(460))/8)+-parseInt(t(467))/9*(-parseInt(t(486))/10))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class TrackClient{constructor(t){const s=W;this[s(490)]=new Map,this[s(475)]=!1,this[s(494)]=t,this[s(496)](),this.platformConfig=function(t){const s=w(t),n=z[s];if(!n)throw new Error("invalid token: "+t);return n}(t.token)}validateConfig(){const t=W;if(!this[t(494)][t(459)])throw new Error(t(495));if(!this.config[t(498)])throw new Error(t(487));if(!this.config[t(489)])throw new Error(t(466));if(!(w(this[t(494)][t(459)])in z))throw new Error(t(469)+this[t(494)][t(459)])}async[b(480)](){const t=b;if(this[t(475)])return;const s=[],n=!1!==this[t(494)][t(485)];for(const r of this[t(471)][t(500)])try{if(r===i[t(503)]&&!n){this[t(494)][t(474)]&&console.log(t(499));continue}let e;switch(r){case i[t(503)]:e=new h(this[t(471)].firebaseConfig);break;case i.SENSORS:e=new u(this[t(494)][t(459)],this[t(494)].platform,this[t(494)][t(489)],this[t(471)].sensorsConfig);break;default:console.warn("unknown provider: "+r);continue}this[t(490)][t(476)](r,e),s[t(465)](e.initialize())}catch(s){console[t(491)](t(483)+r+t(497),s)}await Promise.allSettled(s),this[t(475)]=!0,this[t(494)].debug&&console[t(481)]("Track SDK initialized, enabled providers:",Array.from(this[t(490)].keys()))}async[b(492)](t,s){const n=b;if(!this[n(475)])return void console[n(477)](n(468));this[n(494)][n(474)]&&console.log(n(461)+t,s);const i=[];for(const r of this.adapters[n(493)]())i[n(465)](r[n(492)](t,s));await Promise.allSettled(i)}async[b(504)](t){const s=b;if(!this[s(475)])return void console.warn(s(468));this.config[s(474)]&&console[s(481)]("[Track] Set User ID:",t);const n=[];for(const i of this[s(490)].values())n[s(465)](i.setUserId(t));await Promise[s(501)](n)}async[b(464)](t){const s=b;if(!this[s(475)])return void console[s(477)](s(468));this[s(494)][s(474)]&&console.log(s(488),t);const n=[];for(const i of this[s(490)][s(493)]())n[s(465)](i[s(464)](t));await Promise[s(501)](n)}async[b(502)](){const t=b;if(!this[t(475)])return void console[t(477)](t(468));this.config[t(474)]&&console.log(t(470));const s=[];for(const n of this[t(490)].values())s.push(n[t(502)]());await Promise[t(501)](s)}[b(482)](){const t=b;return Array.from(this[t(490)][t(478)]())}}function N(){var t=["32SgbGKg","13277sDXSua","6010DhxHtX","783710XdSXHe","97871pbrJYC","242604lBScki","30678fUxqQA","316cJoVjP","1766924BGaTQl","501bLqUoP","532ArrsRj"];return(N=function(){return t})()}function S(t,s){return t-=409,N()[t]}!function(){for(var t=S,s=N();;)try{if(225315===parseInt(t(416))/1+-parseInt(t(419))/2*(parseInt(t(410))/3)+parseInt(t(409))/4+parseInt(t(415))/5+-parseInt(t(418))/6*(-parseInt(t(411))/7)+-parseInt(t(412))/8*(parseInt(t(417))/9)+parseInt(t(414))/10*(-parseInt(t(413))/11))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();export{TrackClient,i as TrackProvider};
1
+ import{initializeApp as t}from"firebase/app";import{getAnalytics as s}from"firebase/analytics";import*as n from"sa-sdk-javascript";var e,i;function r(t,s){return t-=430,o()[t]}function o(){var t=["12glWDsv","FIREBASE","2001590tQDYCx","819981fHKBSZ","91862EZzuxl","1985224OWTheH","1OEGyTL","14mZUTpM","1197891rdCOBi","418630aTPpkc","765344vvtCBA"];return(o=function(){return t})()}function a(){const t=["https://www.googletagmanager.com/ns.html?id=","warn","4xbjJJX","height","[GoogleTagManager] Pushed to dataLayer:","gtm.js?id=","[GoogleTagManager] Error pushing to dataLayer:","style","head","[GTM] Already injected, skip","string","parentNode","push","dataLayer","3632CIaSpN","1205405xJWWIc","21140KuVZpu","from","[GTM] Not in browser environment, skip injection","appendChild","body","[GoogleTagManager] Invalid event name:","firstChild","424IAhoXb","width","some","script","visibility","244473xnDKEm","[GTM] Injection failed:","noscript","src","[GoogleTagManager] dataLayer not initialized","none","log","76GDmEdj","iframe","createElement","includes","126720BJWxam","display","async","1582461jKHBqD","insertBefore","error","2364774HORbGx","querySelectorAll","undefined","https://www.googletagmanager.com/gtm.js?id="];return(a=function(){return t})()}function c(){const t=l;return typeof window!==t(270)&&typeof document!==t(270)}function l(t,s){t-=233;return a()[t]}function h(t){const s=l,n=document[s(260)](s(253)),e=document[s(260)](s(259));e[s(254)]=s(272)+t,e[s(275)]="0",e[s(247)]="0",e[s(279)][s(263)]=s(256),e[s(279)][s(250)]="hidden",n[s(242)](e),document[s(243)].firstChild?document.body[s(266)](n,document.body[s(245)]):document[s(243)].appendChild(n)}function d(t,s=!1){const n=l;if(c())if(t)if(function(t){const s=l;if(!c())return!1;const n=!!window[s(236)],e=document[s(269)](s(249)),i=Array[s(240)](e)[s(248)](n=>n.src[s(261)](s(277)+t));return n&&i}(t))s&&console.log(n(281));else try{(function(t){const s=l;window[s(236)]=window[s(236)]||[],window.dataLayer[s(235)]({"gtm.start":(new Date).getTime(),event:"gtm.js"});const n=document[s(260)](s(249));n[s(264)]=!0,n[s(254)]=s(271)+t;const e=document.getElementsByTagName(s(249))[0];e&&e.parentNode?e[s(234)][s(266)](n,e):document[s(280)][s(242)](n)})(t),document[n(243)]?h(t):document.addEventListener("DOMContentLoaded",()=>{h(t)}),s&&console[n(257)]("[GTM] Injected successfully: "+t)}catch(t){console.error(n(252),t)}else s&&console[n(273)]("[GTM] GTM ID is empty, skip injection");else s&&console.warn(n(241))}!function(){for(var t=r,s=o();;)try{if(324898===-parseInt(t(440))/1*(parseInt(t(438))/2)+parseInt(t(431))/3+-parseInt(t(439))/4+-parseInt(t(432))/5*(-parseInt(t(434))/6)+parseInt(t(430))/7*(parseInt(t(433))/8)+-parseInt(t(437))/9+parseInt(t(436))/10)break;s.push(s.shift())}catch(t){s.push(s.shift())}}(),(i=e||(e={}))[r(435)]="firebase",i.SENSORS="sensors",function(){const t=l,s=a();for(;;)try{if(230124===-parseInt(t(237))/1*(parseInt(t(258))/2)+-parseInt(t(251))/3*(-parseInt(t(274))/4)+parseInt(t(238))/5+parseInt(t(268))/6+-parseInt(t(239))/7*(parseInt(t(246))/8)+-parseInt(t(265))/9+-parseInt(t(262))/10)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const p=(t,s)=>{const n=l;if(!t||typeof t!==n(233))return void console[n(267)](n(244),t);(t=>{const s=l;if(typeof window!==s(270)&&window[s(236)])try{window[s(236)][s(235)](t),console[s(257)](s(276),t)}catch(t){console[s(267)](s(278),t)}else console[s(267)](s(255))})({event:t,...s||{}})};function f(){const t=["analytics","453663omFosI","18003952UYuKDR","setUserProperties","2445528ZmyCvO","track","error","setUserId","initialized","794442kDpdKe","507678TuOpzE","6049392PYPqjo","config","2332420yUpIMI","gtmId","firebase initialize failed:","debug","35bhxuhs"];return(f=function(){return t})()}const u=I;function I(t,s){t-=200;return f()[t]}!function(){const t=I,s=f();for(;;)try{if(788670===-parseInt(t(202))/1+-parseInt(t(205))/2+-parseInt(t(211))/3+parseInt(t(212))/4+-parseInt(t(214))/5+parseInt(t(210))/6*(-parseInt(t(200))/7)+parseInt(t(203))/8)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class m{constructor(t,s,n=!1){const e=I;this[e(201)]=null,this[e(209)]=!1,this[e(213)]=t,this.gtmId=s,this.debug=n}async initialize(){const n=I;if(!this[n(209)])try{this[n(215)]&&d(this.gtmId,this[n(217)]);const e=t(this[n(213)]);this[n(201)]=s(e),this[n(209)]=!0}catch(t){throw console[n(207)](n(216),t),t}}async[u(206)](t,s){}async[u(208)](t){}async[u(204)](t){}async clearUserId(){}}const y=g;function w(){const t=["setProfile","initialize","4495DSdori","logout","21679875fnXuwx","showLog","4563352xMCRdN","sensors","heatmap","ajax","sensors sdk not initialized, skip track","sensors sdk not initialized, skip setUserProperties","clearUserId","3619504CBhIgy","1292949BCqOLp","900272coWgmd","platform","track","sensors sdk not initialized, skip setUserId","6594RrCyli","?t=","warn","26600mxdgzq","setUserId","token","sensors sdk not found, please install it by running","setUserProperties","init","error","sensors sdk setUserProperties failed:","config","sensors sdk init failed:","sensors sdk setUserId failed:","84SlKwzo","sensors sdk track failed:","initialized","&v="];return(w=function(){return t})()}function g(t,s){t-=491;return w()[t]}!function(){const t=g,s=w();for(;;)try{if(577902===-parseInt(t(503))/1*(-parseInt(t(514))/2)+-parseInt(t(495))/3+parseInt(t(496))/4+parseInt(t(520))/5*(parseInt(t(500))/6)+parseInt(t(494))/7+parseInt(t(524))/8+-parseInt(t(522))/9)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class k{constructor(t,s,n,e){const i=g;this[i(525)]=null,this[i(516)]=!1,this[i(505)]=t,this[i(497)]=s,this.version=n,this[i(511)]=e}async[y(519)](){const t=y;if(!this[t(516)])try{if(!n)throw new Error(t(506));this[t(525)]=n;const s=encodeURIComponent(this[t(505)]),e=encodeURIComponent(this[t(497)]),i=encodeURIComponent(this.version);this[t(525)][t(508)]({server_url:this[t(511)].serverUrl+(t(501)+s+"&p=")+e+t(517)+i,show_log:this[t(511)][t(523)]??!1,heatmap:this[t(511)][t(526)]??{},is_track_single_page:!0,send_type:t(527)}),this[t(516)]=!0,this.sensors.quick("autoTrack")}catch(s){throw console[t(509)](t(512),s),s}}async[y(498)](t,s){const n=y;if(this[n(516)]&&this[n(525)])try{this[n(525)][n(498)](t,s??{})}catch(t){console.error(n(515),t)}else console[n(502)](n(491))}async[y(504)](t){const s=y;if(this[s(516)]&&this[s(525)])try{this[s(525)].login(t)}catch(t){console.error(s(513),t)}else console.warn(s(499))}async[y(507)](t){const s=y;if(this[s(516)]&&this.sensors)try{this.sensors[s(518)](t)}catch(t){console.error(s(510),t)}else console[s(502)](s(492))}async[y(493)](){const t=y;if(this[t(516)]&&this.sensors)try{this[t(525)][t(521)]()}catch(s){console[t(509)]("sensors sdk clearUserId failed:",s)}}}function b(){var t=["6868253TXhhuJ","undefined","2506398PcueeQ","btoa","base64","78Rfmzmi","2261528ZmKvmc","toString","utf-8","1128filLbp","11036870JPqymD","15oVqSsu","atob","823668vZiTtf","14913yXtXDF","17939jbHTYV"];return(b=function(){return t})()}function z(t,s){return t-=261,b()[t]}function Z(t){var s=z;return"undefined"!=typeof window&&window[s(261)]?window[s(261)](t):Buffer.from(t,s(266))[s(265)]("base64")}function v(t){return JSON.parse((s=t,n=z,typeof window!==n(275)&&window.atob?window[n(270)](s):Buffer.from(s,n(262)).toString(n(266))));var s,n}!function(){for(var t=z,s=b();;)try{if(642505===parseInt(t(273))/1*(parseInt(t(263))/2)+parseInt(t(271))/3+parseInt(t(264))/4+parseInt(t(269))/5*(-parseInt(t(276))/6)+-parseInt(t(274))/7+parseInt(t(267))/8*(parseInt(t(272))/9)+parseInt(t(268))/10)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const M=J;!function(){const t=J,s=N();for(;;)try{if(359557===-parseInt(t(173))/1*(parseInt(t(175))/2)+parseInt(t(172))/3+-parseInt(t(165))/4*(-parseInt(t(171))/5)+-parseInt(t(161))/6+parseInt(t(170))/7+parseInt(t(164))/8+-parseInt(t(166))/9*(-parseInt(t(163))/10))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();const W={"MDE5YjUzNTEyMWJhNzc1ZmIwYTQ1MzY3Njg1NzU1MTU=":{providers:[e.FIREBASE,e.SENSORS],firebaseConfig:v(M(162)),sensorsConfig:v(M(176)),gtmId:M(169)},"MDE5YjUzNTE3ZmFiN2YxZDkwNjg5OWVhMGQyMWJlZGI=":{providers:[e[M(174)],e.SENSORS],firebaseConfig:v(M(168)),sensorsConfig:v("eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19")}};function N(){const t=["8840ebUioO","466232VocMFV","8GBTfbx","9VfVDQN","invalid token: ","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjpkMTQ4OGM3MzI0MWIyZWMzNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctR0gxNk1CQ1NOVyJ9","GTM-MJDRW2W4","3985310KDTNbZ","402455mGOINX","1727022HgsBAD","2bLBHIk","FIREBASE","561186kqojIS","eyJzZXJ2ZXJVcmwiOiJodHRwczovL3N2LWFuYWx5dGljcy5zZy5zZWF2ZXJzZS5haS9zYSIsImhlYXRtYXAiOnsiY2xpY2ttYXAiOiJkZWZhdWx0Iiwic2Nyb2xsX25vdGljZV9tYXAiOiJkZWZhdWx0In19","2666436CUieRQ","eyJhcGlLZXkiOiJBSXphU3lBVVVEam5HdDJKQmdiNVFFYmFFMVFybENvMTdpVWxKWGsiLCJhdXRoRG9tYWluIjoic2VhdmVyc2UtcHJvZHVjdGlvbi5maXJlYmFzZWFwcC5jb20iLCJwcm9qZWN0SWQiOiJzZWF2ZXJzZS1wcm9kdWN0aW9uIiwic3RvcmFnZUJ1Y2tldCI6InNlYXZlcnNlLXByb2R1Y3Rpb24uZmlyZWJhc2VzdG9yYWdlLmFwcCIsIm1lc3NhZ2luZ1NlbmRlcklkIjoiMTAzMzk3MzA4MzE5OCIsImFwcElkIjoiMToxMDMzOTczMDgzMTk4OndlYjo2NmI2ZTNmNmEwZjM2MDkwNmY3NTZmIiwibWVhc3VyZW1lbnRJZCI6IkctN0gySjFTQ05QRCJ9"];return(N=function(){return t})()}function J(t,s){t-=161;return N()[t]}const T=S;function S(t,s){t-=384;return C()[t]}function C(){const t=["Must provide a token","1105356abWdOV","keys","providers","token","15sCKKDt","132036ddNKyX","253aKLiKm","[Track] Clear User ID","trackGTMEvent","warn","allSettled","[Track] Set User ID:","4057713AafXPB","Must provide a platform","Track SDK initialized, enabled providers:","unknown provider: ","adapters","config","debug","15319vFlWyN","setUserId","log","8nghjzf","17610905LVahoh","set","firebaseConfig","initialized","10KLEqge","track SDK not initialized, please call initialize() first","70XhMhPV","initialize","[Track] Set User Properties:","initialize ","clearUserId","version","platformConfig","FIREBASE","validateConfig","track","from","getInitializedProviders","push","554444JFFIWm","setUserProperties","5789wyxboT","platform","error","Invalid token: ","values","10jyWoWP"];return(C=function(){return t})()}!function(){const t=S,s=C();for(;;)try{if(461766===parseInt(t(414))/1*(-parseInt(t(424))/2)+parseInt(t(399))/3*(-parseInt(t(386))/4)+-parseInt(t(422))/5*(parseInt(t(395))/6)+parseInt(t(388))/7*(parseInt(t(417))/8)+-parseInt(t(407))/9*(-parseInt(t(393))/10)+-parseInt(t(401))/11*(-parseInt(t(400))/12)+parseInt(t(418))/13)break;s.push(s.shift())}catch(t){s.push(s.shift())}}();class TrackClient{constructor(t){const s=S;this[s(411)]=new Map,this[s(421)]=!1,this.config=t,this[s(432)](),this[s(430)]=function(t){const s=M,n=Z(t),e=W[n];if(!e)throw new Error(s(167)+t);return e}(t[s(398)])}[T(432)](){const t=T;if(!this[t(412)].token)throw new Error(t(394));if(!this[t(412)].platform)throw new Error(t(408));if(!this[t(412)][t(429)])throw new Error("Must provide a version");if(!(Z(this[t(412)].token)in W))throw new Error(t(391)+this[t(412)][t(398)])}async initialize(){const t=T;if(this[t(421)])return;const s=[],n=!1!==this[t(412)].initializeFirebase;for(const i of this[t(430)][t(397)])try{if(i===e[t(431)]&&!n){this.config.debug&&console[t(416)]("[Track] Skip Firebase initialization (initializeFirebase = false)");continue}let r;switch(i){case e[t(431)]:r=new m(this[t(430)][t(420)],this[t(430)].gtmId,this[t(412)].debug);break;case e.SENSORS:r=new k(this[t(412)][t(398)],this[t(412)][t(389)],this[t(412)][t(429)],this.platformConfig.sensorsConfig);break;default:console.warn(t(410)+i);continue}this[t(411)][t(419)](i,r),s[t(385)](r[t(425)]())}catch(s){console[t(390)](t(427)+i+" adapter failed:",s)}await Promise[t(405)](s),this[t(421)]=!0,this[t(412)][t(413)]&&console.log(t(409),Array[t(434)](this[t(411)].keys()))}async track(t,s){const n=T;if(!this.initialized)return void console[n(404)](n(423));this[n(412)][n(413)]&&console[n(416)]("[Track] "+t,s);const e=[];for(const i of this[n(411)].values())e[n(385)](i[n(433)](t,s));await Promise[n(405)](e)}async[T(415)](t){const s=T;if(!this.initialized)return void console.warn(s(423));this[s(412)].debug&&console.log(s(406),t);const n=[];for(const e of this[s(411)][s(392)]())n[s(385)](e[s(415)](t));await Promise.allSettled(n)}async setUserProperties(t){const s=T;if(!this.initialized)return void console[s(404)](s(423));this[s(412)][s(413)]&&console[s(416)](s(426),t);const n=[];for(const e of this[s(411)][s(392)]())n[s(385)](e[s(387)](t));await Promise[s(405)](n)}async[T(428)](){const t=T;if(!this[t(421)])return void console[t(404)](t(423));this.config[t(413)]&&console[t(416)](t(402));const s=[];for(const n of this[t(411)][t(392)]())s.push(n[t(428)]());await Promise[t(405)](s)}[T(384)](){const t=T;return Array[t(434)](this.adapters[t(396)]())}[T(403)](t,s){p(t,s)}}function F(t,s){return t-=484,Y()[t]}function Y(){var t=["500234qOoZBl","2964096smBwTo","38520QCxcbo","72Idntpy","823JmCXqa","1626819UNLiSY","576FFWSdF","2715860VimdSk","760FUqSYE","1043312OysbDu"];return(Y=function(){return t})()}!function(){for(var t=F,s=Y();;)try{if(350169===parseInt(t(487))/1*(parseInt(t(491))/2)+-parseInt(t(488))/3+-parseInt(t(492))/4+-parseInt(t(490))/5+parseInt(t(484))/6+parseInt(t(493))/7*(parseInt(t(486))/8)+parseInt(t(489))/9*(parseInt(t(485))/10))break;s.push(s.shift())}catch(t){s.push(s.shift())}}();export{TrackClient,e as TrackProvider};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seaverse/track-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Unified analytics SDK for Firebase and Sensors Analytics",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",