@hifilabs/pixel 0.0.3 → 0.0.5
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/dist/index.esm.d.ts +1 -0
- package/dist/index.esm.js +5 -2
- package/dist/index.js +4 -1
- package/dist/index.min.js +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function BalanceAnalytics(): null;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
// src/react/BalanceAnalytics.tsx
|
|
3
|
-
import { useEffect } from "react";
|
|
3
|
+
import { useEffect, Suspense } from "react";
|
|
4
4
|
import { usePathname, useSearchParams } from "next/navigation";
|
|
5
|
-
function
|
|
5
|
+
function BalanceAnalyticsInner() {
|
|
6
6
|
const pathname = usePathname();
|
|
7
7
|
const searchParams = useSearchParams();
|
|
8
8
|
useEffect(() => {
|
|
@@ -14,6 +14,9 @@ function BalanceAnalytics() {
|
|
|
14
14
|
}, [pathname, searchParams]);
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
+
function BalanceAnalytics() {
|
|
18
|
+
return /* @__PURE__ */ React.createElement(Suspense, { fallback: null }, /* @__PURE__ */ React.createElement(BalanceAnalyticsInner, null));
|
|
19
|
+
}
|
|
17
20
|
export {
|
|
18
21
|
BalanceAnalytics
|
|
19
22
|
};
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var BalancePixel = (() => {
|
|
|
33
33
|
// src/react/BalanceAnalytics.tsx
|
|
34
34
|
var import_react = __require("react");
|
|
35
35
|
var import_navigation = __require("next/navigation");
|
|
36
|
-
function
|
|
36
|
+
function BalanceAnalyticsInner() {
|
|
37
37
|
const pathname = (0, import_navigation.usePathname)();
|
|
38
38
|
const searchParams = (0, import_navigation.useSearchParams)();
|
|
39
39
|
(0, import_react.useEffect)(() => {
|
|
@@ -45,6 +45,9 @@ var BalancePixel = (() => {
|
|
|
45
45
|
}, [pathname, searchParams]);
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
|
+
function BalanceAnalytics() {
|
|
49
|
+
return /* @__PURE__ */ React.createElement(import_react.Suspense, { fallback: null }, /* @__PURE__ */ React.createElement(BalanceAnalyticsInner, null));
|
|
50
|
+
}
|
|
48
51
|
|
|
49
52
|
// src/index.ts
|
|
50
53
|
(function() {
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var BalancePixel=(()=>{var
|
|
1
|
+
var BalancePixel=(()=>{var b=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var L=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(o,s)=>(typeof require<"u"?require:o)[s]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var X=(n,o)=>{for(var s in o)b(n,s,{get:o[s],enumerable:!0})},Z=(n,o,s,u)=>{if(o&&typeof o=="object"||typeof o=="function")for(let g of V(o))!W.call(n,g)&&g!==s&&b(n,g,{get:()=>o[g],enumerable:!(u=Q(o,g))||u.enumerable});return n};var ee=n=>Z(b({},"__esModule",{value:!0}),n);var ne={};X(ne,{BalanceAnalytics:()=>R});var S=L("react"),_=L("next/navigation");function te(){let n=(0,_.usePathname)(),o=(0,_.useSearchParams)();return(0,S.useEffect)(()=>{if(typeof window<"u"&&window.balance){let s=window.location.href,u=document.title;window.balance.page({url:s,title:u})}},[n,o]),null}function R(){return React.createElement(S.Suspense,{fallback:null},React.createElement(te,null))}(function(){let n=document.currentScript,o=n?.dataset.artistId,s=n?.dataset.projectId,u=n?.dataset.emulator==="true",g=n?.dataset.debug==="true";if(!o){console.error("[BALANCE Pixel] Error: data-artist-id attribute is required");return}let w="balance_session_id",x="balance_session_timestamp",A="balance_attribution",P="balance_fan_id_hash",C="balance_consent",D=60*60*1e3,v=u?"http://localhost:5001/artist-os-distro/us-central1/pixelEndpoint":"https://us-central1-artist-os-distro.cloudfunctions.net/pixelEndpoint",h=null,l=null,c=null,f={},d=[],I=null,i=(...e)=>{g&&console.log("[BALANCE Pixel]",...e)};function N(){return crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function U(){try{let e=localStorage.getItem(w),t=localStorage.getItem(x);if(e&&t&&Date.now()-parseInt(t,10)<D)return localStorage.setItem(x,Date.now().toString()),e;let r=N();return localStorage.setItem(w,r),localStorage.setItem(x,Date.now().toString()),r}catch{return N()}}function B(){let e=new URLSearchParams(window.location.search),t={};return["source","medium","campaign","content","term"].forEach(r=>{let a=e.get(`utm_${r}`);a&&(t[`utm_${r}`]=a)}),t}function j(){try{let e=localStorage.getItem(A);if(e){f=JSON.parse(e),i("Loaded attribution:",f);return}let t=B();Object.keys(t).length>0&&(f=t,localStorage.setItem(A,JSON.stringify(t)),i("Captured attribution:",f))}catch{}}function F(){try{l=localStorage.getItem(P)}catch{}}function z(){try{let e=localStorage.getItem(C);e&&(c=JSON.parse(e).preferences||null,i("Loaded consent:",c))}catch{}}function H(e){let t=c;c=e;try{let a={preferences:e,method:"explicit",version:1};localStorage.setItem(C,JSON.stringify(a)),i("Consent saved:",e)}catch(a){console.error("[BALANCE Pixel] Could not save consent:",a)}let r=m({event_name:"consent_updated",metadata:{consent_preferences:e,consent_method:"explicit",previous_consent:t||void 0}});p(r)}function M(){return c}function O(e){return c?.[e]===!0}async function J(e){let t=e.toLowerCase().trim(),a=new TextEncoder().encode(t),E=await crypto.subtle.digest("SHA-256",a);return Array.from(new Uint8Array(E)).map(G=>G.toString(16).padStart(2,"0")).join("")}function m(e){let t={artist_id:o,fan_session_id:h,fan_id_hash:l||void 0,timestamp:new Date().toISOString(),source_url:window.location.href,referrer_url:document.referrer||void 0,user_agent:navigator.userAgent,...e,...f};return s&&!e.projectId&&(t.projectId=s),t}function p(e){if(!["identify","consent_updated"].includes(e.event_name)&&!O("analytics")){i(`Event '${e.event_name}' blocked - no analytics consent`);return}d.push(e),i("Event queued:",e.event_name,"(queue:",d.length,")"),d.length>=10&&y()}async function y(){if(d.length===0)return;let e=[...d];d=[],i("Flushing",e.length,"events to",v);try{let t=await fetch(v,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:e}),keepalive:!0});if(!t.ok)throw new Error(`HTTP ${t.status}`);i("Events sent successfully")}catch(t){console.error("[BALANCE Pixel] Failed to send events:",t),d.length<50&&d.push(...e)}}function K(){I&&clearInterval(I),I=window.setInterval(()=>{d.length>0&&y()},5e3)}function T(e={}){let t=m({event_name:"pageview",page_title:e.title||document.title,source_url:e.url||window.location.href});p(t)}function Y(e,t={}){let r=m({event_name:"custom",metadata:{event_type:e,...t}});p(r)}async function q(e,t={}){try{l=await J(e),localStorage.setItem(P,l);let r=e.split("@"),a=r[0].charAt(0)+"***@"+(r[1]||"");i("Fan identified:",{name:t.name||"(no name)",email:a,hash:l.substring(0,16)+"...",traits:t});let E=m({event_name:"identify",fan_id_hash:l,metadata:{email_sha256:l,traits:t,consent_preferences:c||void 0}});p(E)}catch(r){console.error("[BALANCE Pixel] Failed to identify:",r)}}function $(e,t="USD",r={}){let a=m({event_name:"purchase",metadata:{revenue:e,currency:t,...r}});p(a)}function k(){h=U(),F(),z(),c||(c={analytics:!0,marketing:!1,personalization:!1,timestamp:new Date().toISOString()},i("Using default consent (dev mode):",c)),j(),K(),i("Initialized",{artistId:o,projectId:s||"(none - will track to all projects)",sessionId:h,fanIdHash:l,consent:c,useEmulator:u,endpoint:v}),T(),window.addEventListener("beforeunload",()=>{y()}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&y()})}window.balance={track:Y,identify:q,page:T,purchase:$,getSessionId:()=>h,getFanIdHash:()=>l,getAttribution:()=>f,setConsent:H,getConsent:M,hasConsent:O},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",k):k(),i("Pixel script loaded")})();return ee(ne);})();
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hifilabs/pixel",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "BALANCE Pixel - Lightweight browser tracking script for artist fan analytics",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
7
|
+
"types": "./dist/index.esm.d.ts",
|
|
8
8
|
"publishConfig": {
|
|
9
|
-
"access": "
|
|
9
|
+
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "esbuild src/index.ts --bundle --outfile=dist/index.js --watch",
|
|
16
|
+
"build": "node build.js"
|
|
17
|
+
},
|
|
14
18
|
"keywords": [
|
|
15
19
|
"analytics",
|
|
16
20
|
"tracking",
|
|
@@ -36,9 +40,5 @@
|
|
|
36
40
|
"devDependencies": {
|
|
37
41
|
"esbuild": "^0.19.0",
|
|
38
42
|
"typescript": "^5.4.5"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"dev": "esbuild src/index.ts --bundle --outfile=dist/index.js --watch",
|
|
42
|
-
"build": "node build.js"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|