@hifilabs/pixel 0.0.4 → 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 +5 -2
- package/dist/index.js +15 -2
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
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 React, { 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
|
@@ -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,9 +41,9 @@ 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
|
-
function
|
|
46
|
+
function BalanceAnalyticsInner() {
|
|
37
47
|
const pathname = (0, import_navigation.usePathname)();
|
|
38
48
|
const searchParams = (0, import_navigation.useSearchParams)();
|
|
39
49
|
(0, import_react.useEffect)(() => {
|
|
@@ -45,6 +55,9 @@ var BalancePixel = (() => {
|
|
|
45
55
|
}, [pathname, searchParams]);
|
|
46
56
|
return null;
|
|
47
57
|
}
|
|
58
|
+
function BalanceAnalytics() {
|
|
59
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, { fallback: null }, /* @__PURE__ */ import_react.default.createElement(BalanceAnalyticsInner, null));
|
|
60
|
+
}
|
|
48
61
|
|
|
49
62
|
// src/index.ts
|
|
50
63
|
(function() {
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var BalancePixel=(()=>{var
|
|
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);})();
|