@hifilabs/pixel 0.0.5 → 0.0.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/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  // src/react/BalanceAnalytics.tsx
3
- import { useEffect, Suspense } from "react";
3
+ import React, { useEffect, Suspense } from "react";
4
4
  import { usePathname, useSearchParams } from "next/navigation";
5
5
  function BalanceAnalyticsInner() {
6
6
  const pathname = usePathname();
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  var BalancePixel = (() => {
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
7
9
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -22,6 +24,14 @@ var BalancePixel = (() => {
22
24
  }
23
25
  return to;
24
26
  };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
25
35
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
36
 
27
37
  // src/index.ts
@@ -31,7 +41,7 @@ var BalancePixel = (() => {
31
41
  });
32
42
 
33
43
  // src/react/BalanceAnalytics.tsx
34
- var import_react = __require("react");
44
+ var import_react = __toESM(__require("react"));
35
45
  var import_navigation = __require("next/navigation");
36
46
  function BalanceAnalyticsInner() {
37
47
  const pathname = (0, import_navigation.usePathname)();
@@ -46,7 +56,7 @@ var BalancePixel = (() => {
46
56
  return null;
47
57
  }
48
58
  function BalanceAnalytics() {
49
- return /* @__PURE__ */ React.createElement(import_react.Suspense, { fallback: null }, /* @__PURE__ */ React.createElement(BalanceAnalyticsInner, null));
59
+ return /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, { fallback: null }, /* @__PURE__ */ import_react.default.createElement(BalanceAnalyticsInner, null));
50
60
  }
51
61
 
52
62
  // src/index.ts
package/dist/index.min.js CHANGED
@@ -1 +1 @@
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);})();
1
+ var BalancePixel=(()=>{var V=Object.create;var _=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,ee=Object.prototype.hasOwnProperty;var L=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(r,a)=>(typeof require<"u"?require:r)[a]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});var te=(n,r)=>{for(var a in r)_(n,a,{get:r[a],enumerable:!0})},D=(n,r,a,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let g of X(r))!ee.call(n,g)&&g!==a&&_(n,g,{get:()=>r[g],enumerable:!(u=W(r,g))||u.enumerable});return n};var ne=(n,r,a)=>(a=n!=null?V(Z(n)):{},D(r||!n||!n.__esModule?_(a,"default",{value:n,enumerable:!0}):a,n)),re=n=>D(_({},"__esModule",{value:!0}),n);var ae={};te(ae,{BalanceAnalytics:()=>R});var f=ne(L("react")),x=L("next/navigation");function oe(){let n=(0,x.usePathname)(),r=(0,x.useSearchParams)();return(0,f.useEffect)(()=>{if(typeof window<"u"&&window.balance){let a=window.location.href,u=document.title;window.balance.page({url:a,title:u})}},[n,r]),null}function R(){return f.default.createElement(f.Suspense,{fallback:null},f.default.createElement(oe,null))}(function(){let n=document.currentScript,r=n?.dataset.artistId,a=n?.dataset.projectId,u=n?.dataset.emulator==="true",g=n?.dataset.debug==="true";if(!r){console.error("[BALANCE Pixel] Error: data-artist-id attribute is required");return}let w="balance_session_id",v="balance_session_timestamp",A="balance_attribution",P="balance_fan_id_hash",C="balance_consent",U=60*60*1e3,I=u?"http://localhost:5001/artist-os-distro/us-central1/pixelEndpoint":"https://us-central1-artist-os-distro.cloudfunctions.net/pixelEndpoint",y=null,l=null,c=null,m={},d=[],E=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 B(){try{let e=localStorage.getItem(w),t=localStorage.getItem(v);if(e&&t&&Date.now()-parseInt(t,10)<U)return localStorage.setItem(v,Date.now().toString()),e;let o=N();return localStorage.setItem(w,o),localStorage.setItem(v,Date.now().toString()),o}catch{return N()}}function j(){let e=new URLSearchParams(window.location.search),t={};return["source","medium","campaign","content","term"].forEach(o=>{let s=e.get(`utm_${o}`);s&&(t[`utm_${o}`]=s)}),t}function F(){try{let e=localStorage.getItem(A);if(e){m=JSON.parse(e),i("Loaded attribution:",m);return}let t=j();Object.keys(t).length>0&&(m=t,localStorage.setItem(A,JSON.stringify(t)),i("Captured attribution:",m))}catch{}}function z(){try{l=localStorage.getItem(P)}catch{}}function H(){try{let e=localStorage.getItem(C);e&&(c=JSON.parse(e).preferences||null,i("Loaded consent:",c))}catch{}}function M(e){let t=c;c=e;try{let s={preferences:e,method:"explicit",version:1};localStorage.setItem(C,JSON.stringify(s)),i("Consent saved:",e)}catch(s){console.error("[BALANCE Pixel] Could not save consent:",s)}let o=p({event_name:"consent_updated",metadata:{consent_preferences:e,consent_method:"explicit",previous_consent:t||void 0}});h(o)}function J(){return c}function O(e){return c?.[e]===!0}async function K(e){let t=e.toLowerCase().trim(),s=new TextEncoder().encode(t),b=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(b)).map(Q=>Q.toString(16).padStart(2,"0")).join("")}function p(e){let t={artist_id:r,fan_session_id:y,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,...m};return a&&!e.projectId&&(t.projectId=a),t}function h(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&&S()}async function S(){if(d.length===0)return;let e=[...d];d=[],i("Flushing",e.length,"events to",I);try{let t=await fetch(I,{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 Y(){E&&clearInterval(E),E=window.setInterval(()=>{d.length>0&&S()},5e3)}function T(e={}){let t=p({event_name:"pageview",page_title:e.title||document.title,source_url:e.url||window.location.href});h(t)}function q(e,t={}){let o=p({event_name:"custom",metadata:{event_type:e,...t}});h(o)}async function $(e,t={}){try{l=await K(e),localStorage.setItem(P,l);let o=e.split("@"),s=o[0].charAt(0)+"***@"+(o[1]||"");i("Fan identified:",{name:t.name||"(no name)",email:s,hash:l.substring(0,16)+"...",traits:t});let b=p({event_name:"identify",fan_id_hash:l,metadata:{email_sha256:l,traits:t,consent_preferences:c||void 0}});h(b)}catch(o){console.error("[BALANCE Pixel] Failed to identify:",o)}}function G(e,t="USD",o={}){let s=p({event_name:"purchase",metadata:{revenue:e,currency:t,...o}});h(s)}function k(){y=B(),z(),H(),c||(c={analytics:!0,marketing:!1,personalization:!1,timestamp:new Date().toISOString()},i("Using default consent (dev mode):",c)),F(),Y(),i("Initialized",{artistId:r,projectId:a||"(none - will track to all projects)",sessionId:y,fanIdHash:l,consent:c,useEmulator:u,endpoint:I}),T(),window.addEventListener("beforeunload",()=>{S()}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&S()})}window.balance={track:q,identify:$,page:T,purchase:G,getSessionId:()=>y,getFanIdHash:()=>l,getAttribution:()=>m,setConsent:M,getConsent:J,hasConsent:O},document.readyState==="loading"?document.addEventListener("DOMContentLoaded",k):k(),i("Pixel script loaded")})();return re(ae);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hifilabs/pixel",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
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",