@hifilabs/pixel 0.11.1 → 0.12.0
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/browser.js +39 -2
- package/dist/browser.min.js +4 -4
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -75,6 +75,7 @@ var ArtistPixel = (() => {
|
|
|
75
75
|
const tiktokPixelId = currentScript?.dataset.tiktokPixelId || gtmConfig.tiktokPixelId;
|
|
76
76
|
const googleAdsId = currentScript?.dataset.googleAdsId || gtmConfig.googleAdsId;
|
|
77
77
|
const googleAdsConversionLabel = currentScript?.dataset.googleAdsConversionLabel || gtmConfig.googleAdsConversionLabel;
|
|
78
|
+
const googleTagManagerId = currentScript?.dataset.googleTagManagerId || gtmConfig.googleTagManagerId;
|
|
78
79
|
const forwardingConfig = {
|
|
79
80
|
pageview: (currentScript?.dataset.forwardPageview ?? gtmConfig.forwardPageview) !== "false",
|
|
80
81
|
purchase: (currentScript?.dataset.forwardPurchase ?? gtmConfig.forwardPurchase) !== "false",
|
|
@@ -82,7 +83,7 @@ var ArtistPixel = (() => {
|
|
|
82
83
|
lead: (currentScript?.dataset.forwardLead ?? gtmConfig.forwardLead) !== "false",
|
|
83
84
|
custom: (currentScript?.dataset.forwardCustom || gtmConfig.forwardCustom || "").split(",").filter(Boolean)
|
|
84
85
|
};
|
|
85
|
-
const hasPlatformPixels = !!(metaPixelId || tiktokPixelId || googleAdsId);
|
|
86
|
+
const hasPlatformPixels = !!(metaPixelId || tiktokPixelId || googleAdsId || googleTagManagerId);
|
|
86
87
|
const consentUIEnabled = currentScript?.dataset.consentUi === "true";
|
|
87
88
|
const consentStyle = currentScript?.dataset.consentStyle || "brutalist";
|
|
88
89
|
const consentPrimaryColor = currentScript?.dataset.primaryColor;
|
|
@@ -512,6 +513,40 @@ var ArtistPixel = (() => {
|
|
|
512
513
|
};
|
|
513
514
|
document.head.appendChild(script);
|
|
514
515
|
}
|
|
516
|
+
function injectGoogleTagManager() {
|
|
517
|
+
if (!googleTagManagerId)
|
|
518
|
+
return;
|
|
519
|
+
if (document.querySelector(`script[src*="googletagmanager.com/gtm.js?id=${googleTagManagerId}"]`)) {
|
|
520
|
+
log("[Platform:GTM] Already loaded, skipping");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
log("[Platform:GTM] Injecting GTM:", googleTagManagerId);
|
|
524
|
+
window.dataLayer = window.dataLayer || [];
|
|
525
|
+
if (typeof window.gtag !== "function") {
|
|
526
|
+
window.gtag = function(...args) {
|
|
527
|
+
window.dataLayer.push(args);
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
const consentDefaults = marketingConsentGranted ? "granted" : "denied";
|
|
531
|
+
window.gtag("consent", "default", {
|
|
532
|
+
ad_storage: consentDefaults,
|
|
533
|
+
ad_user_data: consentDefaults,
|
|
534
|
+
ad_personalization: consentDefaults,
|
|
535
|
+
analytics_storage: consentDefaults
|
|
536
|
+
});
|
|
537
|
+
window.gtag("set", "wait_for_update", 500);
|
|
538
|
+
window.dataLayer.push({
|
|
539
|
+
"gtm.start": (/* @__PURE__ */ new Date()).getTime(),
|
|
540
|
+
event: "gtm.js"
|
|
541
|
+
});
|
|
542
|
+
const script = document.createElement("script");
|
|
543
|
+
script.async = true;
|
|
544
|
+
script.src = `https://www.googletagmanager.com/gtm.js?id=${googleTagManagerId}`;
|
|
545
|
+
script.onload = () => {
|
|
546
|
+
log("[Platform:GTM] Initialized");
|
|
547
|
+
};
|
|
548
|
+
document.head.appendChild(script);
|
|
549
|
+
}
|
|
515
550
|
function injectPlatformPixels() {
|
|
516
551
|
if (!hasPlatformPixels)
|
|
517
552
|
return;
|
|
@@ -528,6 +563,7 @@ var ArtistPixel = (() => {
|
|
|
528
563
|
injectMetaPixel();
|
|
529
564
|
injectTikTokPixel();
|
|
530
565
|
injectGoogleAds();
|
|
566
|
+
injectGoogleTagManager();
|
|
531
567
|
}
|
|
532
568
|
function setPlatformMarketingConsent(granted) {
|
|
533
569
|
marketingConsentGranted = granted;
|
|
@@ -547,7 +583,8 @@ var ArtistPixel = (() => {
|
|
|
547
583
|
window.gtag("consent", "update", {
|
|
548
584
|
ad_storage: consentValue,
|
|
549
585
|
ad_user_data: consentValue,
|
|
550
|
-
ad_personalization: consentValue
|
|
586
|
+
ad_personalization: consentValue,
|
|
587
|
+
analytics_storage: consentValue
|
|
551
588
|
});
|
|
552
589
|
}
|
|
553
590
|
}
|
package/dist/browser.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ArtistPixel=(()=>{var
|
|
1
|
+
var ArtistPixel=(()=>{var Me=Object.defineProperty;var Oe=(w,h,m)=>h in w?Me(w,h,{enumerable:!0,configurable:!0,writable:!0,value:m}):w[h]=m;var G=(w,h,m)=>(Oe(w,typeof h!="symbol"?h+"":h,m),m);(function(){let w="0.11.0";function h(t){let e="desktop";/ipad|tablet|android(?!.*mobile)/i.test(t)?e="tablet":/mobile|iphone|android.*mobile|blackberry|iemobile/i.test(t)&&(e="mobile");let n="Unknown";/edg/i.test(t)?n="Edge":/opr|opera/i.test(t)?n="Opera":/firefox/i.test(t)?n="Firefox":/chrome/i.test(t)?n="Chrome":/safari/i.test(t)&&(n="Safari");let i="Unknown";return/iphone|ipad/i.test(t)?i="iOS":/android/i.test(t)?i="Android":/windows/i.test(t)?i="Windows":/mac os/i.test(t)?i="macOS":/linux/i.test(t)?i="Linux":/cros/i.test(t)&&(i="ChromeOS"),{device_type:e,browser:n,os:i}}let m=null;function Wt(){if(!m)try{m=h(navigator.userAgent)}catch{m={device_type:"desktop",browser:"Unknown",os:"Unknown"}}return m}let s=document.currentScript,W=s?.dataset.artistId,K=s?.dataset.projectId,Y=K?Kt(K):void 0;function Kt(t){return!t||t.startsWith("release_")||t.startsWith("merch_")||t.startsWith("link_")||t.startsWith("custom_")?t:`custom_${t}`}let J=s?.dataset.emulator==="true",wt=s?.dataset.debug==="true",X=parseInt(s?.dataset.heartbeatInterval||"120000",10),ht=s?.dataset.heartbeat!=="false",yt=s?.dataset.source,bt=s?.dataset.endpoint,p=window.__artistPixelConfig||{},R=s?.dataset.metaPixelId||p.metaPixelId,S=s?.dataset.tiktokPixelId||p.tiktokPixelId,g=s?.dataset.googleAdsId||p.googleAdsId,vt=s?.dataset.googleAdsConversionLabel||p.googleAdsConversionLabel,D=s?.dataset.googleTagManagerId||p.googleTagManagerId,_={pageview:(s?.dataset.forwardPageview??p.forwardPageview)!=="false",purchase:(s?.dataset.forwardPurchase??p.forwardPurchase)!=="false",addToCart:(s?.dataset.forwardAddToCart??p.forwardAddToCart)!=="false",lead:(s?.dataset.forwardLead??p.forwardLead)!=="false",custom:(s?.dataset.forwardCustom||p.forwardCustom||"").split(",").filter(Boolean)},M=!!(R||S||g||D),Q=s?.dataset.consentUi==="true",Yt=s?.dataset.consentStyle||"brutalist",Jt=s?.dataset.primaryColor,Xt=s?.dataset.bannerPosition||"bottom",kt=s?.dataset.excludePages?.split(",").filter(Boolean)||[],_t=s?.dataset.trackFileDownloads==="true",Qt=s?.dataset.hashRouting==="true";function Zt(){if(yt)return yt;let t=typeof window.dataLayer<"u"&&Array.isArray(window.dataLayer),e=typeof window.gtag=="function";return t&&e?"gtm":"pixel"}let z="pixel";if(!W){C(" Error: data-artist-id attribute is required");return}let xt="session_id",Z="session_timestamp",It="attribution",Ct="fan_id_hash",tt="visitor_id",$="artistPixel_consent",te=365*24*60*60*1e3,ee=30*24*60*60*1e3,ne=60*60*1e3,P="balance_";function ae(t){let e=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp("^"+e+"$")}function ie(t){if(kt.length===0)return!1;try{let e=new URL(t,window.location.origin).pathname;return kt.some(n=>ae(n).test(e))}catch{return!1}}let oe=[".pdf",".zip",".tar",".gz",".rar",".7z",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".mp3",".wav",".flac",".aac",".ogg",".mp4",".mov",".avi",".mkv",".webm",".exe",".dmg",".pkg",".deb",".rpm",".csv",".json",".xml",".txt"];function St(t){try{let e=new URL(t,window.location.origin).pathname.toLowerCase();return oe.some(n=>e.endsWith(n))}catch{return!1}}function re(t,e){try{let i=new URL(t,window.location.origin).pathname.split("/").pop()||"unknown",c=i.includes(".")?i.split(".").pop():"unknown";a("File download tracked:",{url:t,fileName:i,fileExtension:c});let d=x({event_name:"custom",metadata:{event_type:"file_download",file_url:t,file_name:i,file_extension:c,link_text:e?.textContent?.trim().substring(0,100)||""}});I(d)}catch(n){C("Failed to track file download:",n)}}let se="https://balance-pixel-proxy.hifilabs.workers.dev",Pt="https://us-central1-artist-os-distro.cloudfunctions.net/ingestEvents",E=bt||(J?"http://localhost:5001/artist-os-distro/us-central1/ingestEvents":se),O=null,f=null,y=null,u=null,T={},et={},b=[],nt=null,v="session",L=null,at=0,it=0,A=0,U=!0,ot=0,rt=!1,ce=2*60*1e3,Et=Date.now(),j=!1,de=!wt,a=(...t)=>{wt&&console.log("[artistPixel]",...t)},C=(...t)=>{de||console.error("[artistPixel]",...t)},st={base:`
|
|
2
2
|
:host {
|
|
3
3
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
4
4
|
position: fixed;
|
|
@@ -83,12 +83,12 @@ var ArtistPixel=(()=>{var Re=Object.defineProperty;var De=(p,w,m)=>w in p?Re(p,w
|
|
|
83
83
|
}
|
|
84
84
|
.btn.accept { background: #fff; color: #000; border-color: #fff; }
|
|
85
85
|
.btn:hover { opacity: 0.8; }
|
|
86
|
-
`};class le{constructor(e){
|
|
86
|
+
`};class le{constructor(e){G(this,"container",null);G(this,"shadow",null);G(this,"config");if(this.config=e,this.hasStoredConsent()){a("ConsentManager: Consent already exists, not showing banner");return}this.container=document.createElement("div"),this.container.id="artistPixel-consent-manager",this.shadow=this.container.attachShadow({mode:"closed"}),this.render(),document.body.appendChild(this.container),a("ConsentManager: Banner rendered")}hasStoredConsent(){try{return window._balanceConsentNeedsRefresh?!1:localStorage.getItem($)!==null}catch{return!1}}render(){if(!this.shadow)return;let e=this.config.style||"brutalist",n=st.base,i=st[e]||st.brutalist,c=this.config.position==="top"?"top: 0;":"bottom: 0;",d=this.config.primaryColor?`.btn.accept { background: ${this.config.primaryColor} !important; border-color: ${this.config.primaryColor} !important; color: #fff !important; }`:"";this.shadow.innerHTML=`
|
|
87
87
|
<style>
|
|
88
88
|
${n}
|
|
89
89
|
:host { ${c} }
|
|
90
90
|
${i}
|
|
91
|
-
${
|
|
91
|
+
${d}
|
|
92
92
|
</style>
|
|
93
93
|
<div class="banner" role="dialog" aria-label="Cookie consent" aria-modal="false">
|
|
94
94
|
<p class="text">
|
|
@@ -99,4 +99,4 @@ var ArtistPixel=(()=>{var Re=Object.defineProperty;var De=(p,w,m)=>w in p?Re(p,w
|
|
|
99
99
|
<button id="accept" class="btn accept">Accept</button>
|
|
100
100
|
</div>
|
|
101
101
|
</div>
|
|
102
|
-
`,this.shadow.getElementById("accept")?.addEventListener("click",()=>this.handleConsent(!0)),this.shadow.getElementById("decline")?.addEventListener("click",()=>this.handleConsent(!1))}handleConsent(e){window.balance?.setConsent&&window.balance.setConsent({analytics:e,marketing:e,personalization:e,timestamp:new Date().toISOString()}),e&&!window._balanceInitialPageviewFired&&(window._balanceInitialPageviewFired=!0,window.balance?.page&&window.balance.page(),dt(),a("Initial pageview fired after consent granted")),this.remove()}remove(){this.container&&(this.container.remove(),this.container=null,this.shadow=null,a("ConsentManager: Banner removed"))}}let Et=!1,rt=!1;function de(){if(!R)return;if(window.fbq){a("[Platform:Meta] Already loaded, skipping");return}a("[Platform:Meta] Injecting pixel:",R);let t=function(...n){t.callMethod?t.callMethod.apply(t,n):t.queue.push(n)};window._fbq||(window._fbq=t),t.push=t,t.loaded=!0,t.version="2.0",t.queue=[],window.fbq=t;let e=document.createElement("script");e.async=!0,e.src="https://connect.facebook.net/en_US/fbevents.js",e.onload=()=>{window.fbq("init",R),_.pageview&&window.fbq("track","PageView"),a("[Platform:Meta] Initialized and PageView tracked")},document.head.appendChild(e)}function ue(){if(!S)return;if(window.ttq?._i?.[S]){a("[Platform:TikTok] Already loaded, skipping");return}a("[Platform:TikTok] Injecting pixel:",S);let t=window,e="ttq";t.TiktokAnalyticsObject=e;let n=t[e]=t[e]||[];n.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","holdConsent","revokeConsent","grantConsent"],n.setAndDefer=function(i,c){i[c]=function(...l){i.push([c].concat(l))}};for(let i=0;i<n.methods.length;i++)n.setAndDefer(n,n.methods[i]);n.instance=function(i){let c=n._i[i]||[];for(let l=0;l<n.methods.length;l++)n.setAndDefer(c,n.methods[l]);return c},n.load=function(i){let c="https://analytics.tiktok.com/i18n/pixel/events.js";n._i=n._i||{},n._i[i]=[],n._i[i]._u=c,n._t=n._t||{},n._t[i]=+new Date,n._o=n._o||{};let l=document.createElement("script");l.type="text/javascript",l.async=!0,l.src=c+"?sdkid="+i+"&lib="+e,document.head.appendChild(l)},n.load(S),_.pageview&&n.page(),a("[Platform:TikTok] Initialized and page() tracked")}function fe(){if(!f)return;if(window.dataLayer=window.dataLayer||[],typeof window.gtag!="function"&&(window.gtag=function(...e){window.dataLayer.push(e)}),document.querySelector('script[src*="googletagmanager.com/gtag/js"]')){a("[Platform:GoogleAds] gtag.js already loaded, configuring"),window.gtag("config",f);return}a("[Platform:GoogleAds] Injecting gtag:",f),window.gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"granted",analytics_storage:"granted"});let t=document.createElement("script");t.async=!0,t.src=`https://www.googletagmanager.com/gtag/js?id=${f}`,t.onload=()=>{window.gtag("js",new Date),window.gtag("config",f),a("[Platform:GoogleAds] Initialized")},document.head.appendChild(t)}function ge(){if(D){if(Et){a("[Platform] Already loaded, skipping");return}if(!rt){a("[Platform] Marketing consent not granted, deferring");return}a("[Platform] Injecting platform pixels (consent granted)"),Et=!0,de(),ue(),fe()}}function Tt(t){if(rt=t,a("[Platform] Marketing consent:",t?"granted":"denied"),t&&ge(),window.ttq&&(t?window.ttq.grantConsent?.():window.ttq.revokeConsent?.()),typeof window.gtag=="function"){let e=t?"granted":"denied";window.gtag("consent","update",{ad_storage:e,ad_user_data:e,ad_personalization:e})}}function st(t){if(!D||!rt)return!1;let e=t.toLowerCase();return e==="pageview"||e==="page_view"?_.pageview:e==="purchase"?_.purchase:e==="addtocart"||e==="add_to_cart"?_.addToCart:e==="lead"||e==="form_submit"?_.lead:_.custom.length>0?_.custom.some(n=>n.toLowerCase()===e):!1}function me(){st("pageview")&&(a("[Platform] Forwarding PageView"),window.fbq&&window.fbq("track","PageView"),window.ttq&&window.ttq.page())}function pe(t,e,n){if(st("purchase")&&(a("[Platform] Forwarding Purchase:",t,e),window.fbq&&window.fbq("track","Purchase",{value:t,currency:e,content_ids:n?.contentIds,content_type:n?.contentType||"product",order_id:n?.transactionId}),window.ttq&&window.ttq.track("CompletePayment",{value:t,currency:e,order_id:n?.transactionId}),typeof window.gtag=="function"&&f)){let i=yt?`${f}/${yt}`:f;window.gtag("event","conversion",{send_to:i,value:t,currency:e,transaction_id:n?.transactionId}),window.gtag("event","purchase",{send_to:f,value:t,currency:e,transaction_id:n?.transactionId})}}function we(t,e){if(!st(t))return;let n=t.toLowerCase();a("[Platform] Forwarding custom event:",t);let i={addtocart:"AddToCart",add_to_cart:"AddToCart",lead:"Lead",form_submit:"Lead",viewcontent:"ViewContent",view_content:"ViewContent",search:"Search",subscribe:"Subscribe",contact:"Contact",completeregistration:"CompleteRegistration",complete_registration:"CompleteRegistration",initiatecheckout:"InitiateCheckout",initiate_checkout:"InitiateCheckout"},c={addtocart:"AddToCart",add_to_cart:"AddToCart",lead:"SubmitForm",form_submit:"SubmitForm",viewcontent:"ViewContent",view_content:"ViewContent",search:"Search",subscribe:"Subscribe",contact:"Contact",completeregistration:"CompleteRegistration",complete_registration:"CompleteRegistration",initiatecheckout:"InitiateCheckout",initiate_checkout:"InitiateCheckout"},l={addtocart:"add_to_cart",add_to_cart:"add_to_cart",lead:"generate_lead",form_submit:"generate_lead",viewcontent:"view_item",view_content:"view_item",search:"search",subscribe:"subscribe",contact:"contact",completeregistration:"sign_up",complete_registration:"sign_up",initiatecheckout:"begin_checkout",initiate_checkout:"begin_checkout"};if(window.fbq){let r=i[n];r?window.fbq("track",r,e):window.fbq("trackCustom",t,e)}if(window.ttq){let r=c[n]||t;window.ttq.track(r,e)}if(typeof window.gtag=="function"&&f){let r=l[n]||t;window.gtag("event",r,{send_to:f,...e})}}function Lt(){try{return v==="local"?localStorage:sessionStorage}catch{return null}}function H(t){let e=Lt();if(!e)return null;try{let n=P+t,i=e.getItem(n);if(!i&&v==="session")try{i=localStorage.getItem(n)}catch{}return i}catch{return null}}function q(t,e){let n=Lt();if(n)try{n.setItem(P+t,e)}catch{}}function At(){if(v!=="local"){a("Upgrading storage tier: session -> local");try{let t=[];for(let e=0;e<sessionStorage.length;e++){let n=sessionStorage.key(e);n?.startsWith(P)&&t.push(n)}for(let e of t){let n=sessionStorage.getItem(e);n&&localStorage.setItem(e,n)}for(let e of t)sessionStorage.removeItem(e);v="local",a(`Storage tier upgraded, migrated ${t.length} items`)}catch(t){C(" Storage migration failed:",t)}}}function $(){return crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function he(){try{let t=H(_t),e=H(X);if(t&&e&&Date.now()-parseInt(e,10)<ee)return q(X,Date.now().toString()),t;let n=$();return q(_t,n),q(X,Date.now().toString()),n}catch{return $()}}function be(){let t=new URLSearchParams(window.location.search),e={};return["source","medium","campaign","content","term"].forEach(n=>{let i=t.get(`utm_${n}`);i&&(e[`utm_${n}`]=i)}),e}function ye(){try{let t=H(xt);if(t){T=JSON.parse(t),a("Loaded attribution:",T);return}let e=be();Object.keys(e).length>0&&(T=e,q(xt,JSON.stringify(e)),a("Captured attribution:",T))}catch{}}function ve(){try{b=H(It)}catch{}}function ct(){try{let t=localStorage.getItem(P+Q);if(t)return t;let e=$();return localStorage.setItem(P+Q,e),a("Created persistent visitor ID:",e.substring(0,8)+"..."),e}catch{return a("localStorage unavailable, using session ID as fallback"),O||$()}}function ke(){try{g=localStorage.getItem(P+Q),g&&a("Loaded visitor ID:",g.substring(0,8)+"...")}catch{}}function _e(){try{let t=localStorage.getItem(z);if(t){let e=JSON.parse(t);if(e.expiresAt&&Date.now()>e.expiresAt){a("Consent expired - clearing stored consent"),localStorage.removeItem(z),u=null;return}if(e.expiresAt){let n=e.expiresAt-Date.now();n>0&&n<te&&(a("Consent nearing expiration - will prompt for refresh"),window._balanceConsentNeedsRefresh=!0)}u=e.preferences||null,a("Loaded consent:",u)}}catch{}}function Rt(t){let e=u;u=t;try{let i={preferences:t,method:"explicit",version:1,expiresAt:Date.now()+Zt};localStorage.setItem(z,JSON.stringify(i)),a("Consent saved with TTL:",t),window._balanceConsentNeedsRefresh=!1}catch(i){C(" Could not save consent:",i)}t.analytics===!0&&(At(),g||(g=ct()));let n=x({event_name:"consent_updated",metadata:{consent_preferences:t,consent_method:"explicit",previous_consent:e||void 0}});I(n);try{window.dispatchEvent(new CustomEvent("artistPixel:consent:updated",{detail:t})),a("DOM event artistPixel:consent:updated dispatched")}catch{}D&&Tt(t.marketing===!0)}function xe(){return u}function Ie(t){return u?.[t]===!0}function Ce(t){for(let[e,n]of Object.entries(t))try{let i=Dt(e);Z[i]=n}catch{Z[e]=n}a("Registered",Object.keys(t).length,"links for tracking enrichment")}function Dt(t){try{let e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}${e.search}`}catch{return t}}function Se(t){let e=Dt(t);return Z[e]||null}async function Pe(t){let e=t.toLowerCase().trim(),i=new TextEncoder().encode(e),c=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(c)).map(r=>r.toString(16).padStart(2,"0")).join("")}function x(t){let e=Wt(),n={artist_id:B,fan_session_id:O,visitor_id:g||ct(),fan_id_hash:b||void 0,timestamp:new Date().toISOString(),source_url:window.location.href,referrer_url:document.referrer||void 0,user_agent:navigator.userAgent,device_type:e.device_type,browser:e.browser,os:e.os,tracking_source:N,...t,...T};return G&&!t.projectId&&(n.projectId=G),n}function I(t){y.push(t),a("Event queued:",t.event_name,"(queue:",y.length,")"),y.length>=10&&j()}async function j(){if(y.length===0)return;let t=[...y];y=[],a("Flushing",t.length,"events to",E);try{let e=await fetch(E,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t}),keepalive:!0});if(!e.ok)throw new Error(`HTTP ${e.status}`);a("Events sent successfully")}catch(e){if(C(" Failed to send events, trying fallback:",e),E!==St&&!K)try{if((await fetch(St,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t}),keepalive:!0})).ok){a("Events sent via fallback (no geo)");return}}catch(n){C(" Fallback also failed:",n)}y.length<50&&y.push(...t)}}function Ee(){tt&&clearInterval(tt),tt=window.setInterval(()=>{y.length>0&&j()},5e3)}function lt(){A||(et=Date.now()),A=Date.now(),M=!0,a("Active time tracking started/resumed")}function Ot(){A&&M&&(nt+=Date.now()-A),M=!1,a("Active time tracking paused, accumulated:",nt,"ms")}function Mt(){let t=nt;return M&&A&&(t+=Date.now()-A),t}function Te(){Pt=Date.now(),U&&(U=!1,lt(),a("User returned from idle"))}function Le(){if(document.visibilityState==="hidden"){a("Skipping heartbeat - tab hidden");return}if(Date.now()-Pt>se){U||(U=!0,Ot(),a("User idle - pausing heartbeat"));return}let t=Mt(),e=Math.round(t/1e3),n=x({event_name:"engagement_heartbeat",metadata:{time_on_page_seconds:e,time_on_page_ms:t,heartbeat_interval_ms:Y,is_active:M&&!U}});I(n),at++,a("Heartbeat sent:",e,"seconds active")}function dt(){if(!wt){a('Heartbeat disabled via data-heartbeat="false"');return}L&&clearInterval(L),lt(),L=window.setInterval(()=>{Le()},Y),a("Heartbeat started with interval:",Y,"ms")}function ut(){if(!it){if(it=!0,L&&(clearInterval(L),L=null),wt){let t=et?Date.now()-et:0,e=Mt(),n=x({event_name:"engagement_summary",metadata:{total_time_ms:t,active_time_ms:e,heartbeat_samples:at,page_path:window.location.pathname}});if(navigator.sendBeacon&&E){let i=JSON.stringify({events:[n]});navigator.sendBeacon(E,i),a("Engagement summary sent via sendBeacon:",Math.round(e/1e3),"seconds active")}else I(n),a("Engagement summary enqueued:",Math.round(e/1e3),"seconds active")}at=0}}function F(t={}){let e=t.url||window.location.href;if(ae(e)){a("Page excluded from tracking:",e);return}let n=x({event_name:"pageview",page_title:t.title||document.title,source_url:e});I(n),me()}function ft(t,e={}){let n=x({event_name:"custom",metadata:{event_type:t,...e}});I(n),we(t,e)}async function Ut(t,e={}){try{if(u&&u.analytics===!1){a("Identify skipped - user declined analytics consent");return}b=await Pe(t),u?.analytics===!0&&At(),q(It,b);let n=t.split("@"),i=n[0].charAt(0)+"***@"+(n[1]||"");a("Fan identified:",{name:e.name||"(no name)",email:i,hash:b.substring(0,16)+"...",traits:e,storageTier:v});let c=x({event_name:"identify",fan_id_hash:b,metadata:{email_sha256:b,email_display:i,traits:e,consent_preferences:u||void 0,storage_tier:v}});I(c)}catch(n){C(" Failed to identify:",n)}}function qt(t,e="USD",n={}){let i=x({event_name:"purchase",metadata:{revenue:t,currency:e,...n}});I(i),pe(t,e,n)}function jt(){N=Qt(),a("Tracking source detected:",N),_e(),u?.analytics===!0?(v="local",a("Storage tier: local (analytics consent granted)")):(v="session",a("Storage tier: session (privacy by default)")),O=he(),ve(),ke(),g||(g=ct()),u||a(J?"Consent UI enabled, waiting for explicit user consent (Tier 0 mode)":"No consent - operating in privacy-first mode (session storage only, limited tracking)"),D&&u?.marketing===!0?(a("[Platform] Marketing consent already granted, initializing platform pixels"),Tt(!0)):D&&a("[Platform] Platform pixels configured:",{meta:R||"(none)",tiktok:S||"(none)",googleAds:f||"(none)"}),ye(),Ee(),a("Initialized",{artistId:B,projectId:G||"(none - will track to all projects)",rawProjectId:W||"(none)",sessionId:O,visitorId:g?g.substring(0,8)+"...":null,fanIdHash:b,consent:u,storageTier:v,trackingSource:N,useEmulator:K,endpoint:E}),u?.analytics===!0?(window._balanceInitialPageviewFired=!0,F(),dt(),a("Full tracking enabled (user consented)")):J?a("Tracking dormant - waiting for explicit consent via ConsentManager"):(window._balanceInitialPageviewFired=!0,F(),dt(),a("Privacy-first tracking enabled (session-scoped, visitor_id for deduplication)")),["mousemove","keydown","scroll","touchstart"].forEach(r=>{document.addEventListener(r,Te,{passive:!0})});let t=window.location.hostname;function e(r){try{let o=new URL(r).hostname.toLowerCase();return o.includes("spotify")?"spotify":o.includes("apple")||o.includes("music.apple")?"apple_music":o.includes("youtube")||o.includes("youtu.be")?"youtube":o.includes("soundcloud")?"soundcloud":o.includes("tidal")?"tidal":o.includes("deezer")?"deezer":o.includes("amazon")||o.includes("music.amazon")?"amazon_music":o.includes("bandcamp")?"bandcamp":o.includes("lnk.to")||o.includes("linkfire")?"linkfire":o.includes("linktr.ee")?"linktree":o.includes("shop")||o.includes("store")||o.includes("merch")?"shop":o.includes("ticketmaster")||o.includes("eventbrite")||o.includes("dice.fm")?"tickets":o.includes("instagram")?"instagram":o.includes("twitter")||o.includes("x.com")?"twitter":o.includes("tiktok")?"tiktok":o.includes("facebook")?"facebook":"external"}catch{return"external"}}function n(r){try{return new URL(r,window.location.origin).hostname!==t}catch{return!1}}function i(r,o){let d=e(r),k=Se(r),$t=k?.title||o?.textContent?.trim().substring(0,100)||"",Vt=k?.id||o?.id||o?.getAttribute("data-link-id")||void 0,Bt=k?.category;a("External link clicked:",{url:r,platform:d,linkText:$t,linkId:Vt,fromRegistry:!!k}),ft("page_link_click",{link_url:r,link_text:$t,link_id:Vt,platform:d,link_type:"external",...Bt&&{link_category:Bt},...k&&Object.fromEntries(Object.entries(k).filter(([mt])=>!["title","id","category"].includes(mt)).map(([mt,Ae])=>[`link_${mt}`,Ae]))})}let c=window.open;if(window.open=function(r,o,d){if(r){let k=r.toString();n(k)&&i(k)}return c.call(window,r,o,d)},a("window.open interception enabled (always on)"),s?.dataset.autoTrackLinks==="true"&&(document.addEventListener("click",r=>{let d=r.target.closest("a");if(d&&d.href&&n(d.href)){if(kt&&(Ct(d.href)||d.hasAttribute("download")))return;i(d.href,d)}},{capture:!0,passive:!0}),a("External link click listener enabled (opt-in)")),kt&&(document.addEventListener("click",r=>{let d=r.target.closest("a");d?.href&&(Ct(d.href)||d.hasAttribute("download"))&&oe(d.href,d)},{capture:!0,passive:!0}),a("File download tracking enabled")),Xt){let r=window.location.href;window.addEventListener("hashchange",()=>{let o=window.location.href;o!==r&&(r=o,setTimeout(()=>{F({title:document.title,url:o})},0))}),a("Hash routing tracking enabled")}document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(Ot(),ut(),j()):(lt(),it=!1)}),window.addEventListener("pagehide",()=>{ut(),j()}),window.addEventListener("beforeunload",()=>{ut(),j()})}if(window.balance?._version&&window.balance._version!==p){console.warn(`[artistPixel] Version conflict: ${window.balance._version} already loaded, skipping ${p}`);return}let gt=window.balance?.q||[];function Ft(){if(gt.length>0){a("Processing",gt.length,"queued commands");for(let t of gt){let[e,...n]=t;switch(e){case"track":ft(n[0],n[1]);break;case"identify":Ut(n[0],n[1]);break;case"page":F(n[0]);break;case"purchase":qt(n[0],n[1],n[2]);break;case"setConsent":Rt(n[0]);break;default:a("Unknown queued command:",e)}}}}let Nt={track:ft,identify:Ut,page:F,purchase:qt,getSessionId:()=>O,getVisitorId:()=>g,getFanIdHash:()=>b,getAttribution:()=>T,setConsent:Rt,getConsent:xe,hasConsent:Ie,registerLinks:Ce,_version:p};window.artistPixel=Nt,window.balance=Nt;function zt(){J&&!u&&new le({style:Kt,primaryColor:Yt,position:Jt})}let Ht=window.requestIdleCallback||(t=>setTimeout(t,1));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{jt(),Ft(),Ht(()=>zt())}):(jt(),Ft(),Ht(()=>zt())),a("Pixel script loaded")})();})();
|
|
102
|
+
`,this.shadow.getElementById("accept")?.addEventListener("click",()=>this.handleConsent(!0)),this.shadow.getElementById("decline")?.addEventListener("click",()=>this.handleConsent(!1))}handleConsent(e){window.balance?.setConsent&&window.balance.setConsent({analytics:e,marketing:e,personalization:e,timestamp:new Date().toISOString()}),e&&!window._balanceInitialPageviewFired&&(window._balanceInitialPageviewFired=!0,window.balance?.page&&window.balance.page(),ut(),a("Initial pageview fired after consent granted")),this.remove()}remove(){this.container&&(this.container.remove(),this.container=null,this.shadow=null,a("ConsentManager: Banner removed"))}}let Tt=!1,H=!1;function ue(){if(!R)return;if(window.fbq){a("[Platform:Meta] Already loaded, skipping");return}a("[Platform:Meta] Injecting pixel:",R);let t=function(...n){t.callMethod?t.callMethod.apply(t,n):t.queue.push(n)};window._fbq||(window._fbq=t),t.push=t,t.loaded=!0,t.version="2.0",t.queue=[],window.fbq=t;let e=document.createElement("script");e.async=!0,e.src="https://connect.facebook.net/en_US/fbevents.js",e.onload=()=>{window.fbq("init",R),_.pageview&&window.fbq("track","PageView"),a("[Platform:Meta] Initialized and PageView tracked")},document.head.appendChild(e)}function ge(){if(!S)return;if(window.ttq?._i?.[S]){a("[Platform:TikTok] Already loaded, skipping");return}a("[Platform:TikTok] Injecting pixel:",S);let t=window,e="ttq";t.TiktokAnalyticsObject=e;let n=t[e]=t[e]||[];n.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","holdConsent","revokeConsent","grantConsent"],n.setAndDefer=function(i,c){i[c]=function(...d){i.push([c].concat(d))}};for(let i=0;i<n.methods.length;i++)n.setAndDefer(n,n.methods[i]);n.instance=function(i){let c=n._i[i]||[];for(let d=0;d<n.methods.length;d++)n.setAndDefer(c,n.methods[d]);return c},n.load=function(i){let c="https://analytics.tiktok.com/i18n/pixel/events.js";n._i=n._i||{},n._i[i]=[],n._i[i]._u=c,n._t=n._t||{},n._t[i]=+new Date,n._o=n._o||{};let d=document.createElement("script");d.type="text/javascript",d.async=!0,d.src=c+"?sdkid="+i+"&lib="+e,document.head.appendChild(d)},n.load(S),_.pageview&&n.page(),a("[Platform:TikTok] Initialized and page() tracked")}function fe(){if(!g)return;if(window.dataLayer=window.dataLayer||[],typeof window.gtag!="function"&&(window.gtag=function(...e){window.dataLayer.push(e)}),document.querySelector('script[src*="googletagmanager.com/gtag/js"]')){a("[Platform:GoogleAds] gtag.js already loaded, configuring"),window.gtag("config",g);return}a("[Platform:GoogleAds] Injecting gtag:",g),window.gtag("consent","default",{ad_storage:"granted",ad_user_data:"granted",ad_personalization:"granted",analytics_storage:"granted"});let t=document.createElement("script");t.async=!0,t.src=`https://www.googletagmanager.com/gtag/js?id=${g}`,t.onload=()=>{window.gtag("js",new Date),window.gtag("config",g),a("[Platform:GoogleAds] Initialized")},document.head.appendChild(t)}function me(){if(!D)return;if(document.querySelector(`script[src*="googletagmanager.com/gtm.js?id=${D}"]`)){a("[Platform:GTM] Already loaded, skipping");return}a("[Platform:GTM] Injecting GTM:",D),window.dataLayer=window.dataLayer||[],typeof window.gtag!="function"&&(window.gtag=function(...n){window.dataLayer.push(n)});let t=H?"granted":"denied";window.gtag("consent","default",{ad_storage:t,ad_user_data:t,ad_personalization:t,analytics_storage:t}),window.gtag("set","wait_for_update",500),window.dataLayer.push({"gtm.start":new Date().getTime(),event:"gtm.js"});let e=document.createElement("script");e.async=!0,e.src=`https://www.googletagmanager.com/gtm.js?id=${D}`,e.onload=()=>{a("[Platform:GTM] Initialized")},document.head.appendChild(e)}function pe(){if(M){if(Tt){a("[Platform] Already loaded, skipping");return}if(!H){a("[Platform] Marketing consent not granted, deferring");return}a("[Platform] Injecting platform pixels (consent granted)"),Tt=!0,ue(),ge(),fe(),me()}}function Lt(t){if(H=t,a("[Platform] Marketing consent:",t?"granted":"denied"),t&&pe(),window.ttq&&(t?window.ttq.grantConsent?.():window.ttq.revokeConsent?.()),typeof window.gtag=="function"){let e=t?"granted":"denied";window.gtag("consent","update",{ad_storage:e,ad_user_data:e,ad_personalization:e,analytics_storage:e})}}function ct(t){if(!M||!H)return!1;let e=t.toLowerCase();return e==="pageview"||e==="page_view"?_.pageview:e==="purchase"?_.purchase:e==="addtocart"||e==="add_to_cart"?_.addToCart:e==="lead"||e==="form_submit"?_.lead:_.custom.length>0?_.custom.some(n=>n.toLowerCase()===e):!1}function we(){ct("pageview")&&(a("[Platform] Forwarding PageView"),window.fbq&&window.fbq("track","PageView"),window.ttq&&window.ttq.page())}function he(t,e,n){if(ct("purchase")&&(a("[Platform] Forwarding Purchase:",t,e),window.fbq&&window.fbq("track","Purchase",{value:t,currency:e,content_ids:n?.contentIds,content_type:n?.contentType||"product",order_id:n?.transactionId}),window.ttq&&window.ttq.track("CompletePayment",{value:t,currency:e,order_id:n?.transactionId}),typeof window.gtag=="function"&&g)){let i=vt?`${g}/${vt}`:g;window.gtag("event","conversion",{send_to:i,value:t,currency:e,transaction_id:n?.transactionId}),window.gtag("event","purchase",{send_to:g,value:t,currency:e,transaction_id:n?.transactionId})}}function ye(t,e){if(!ct(t))return;let n=t.toLowerCase();a("[Platform] Forwarding custom event:",t);let i={addtocart:"AddToCart",add_to_cart:"AddToCart",lead:"Lead",form_submit:"Lead",viewcontent:"ViewContent",view_content:"ViewContent",search:"Search",subscribe:"Subscribe",contact:"Contact",completeregistration:"CompleteRegistration",complete_registration:"CompleteRegistration",initiatecheckout:"InitiateCheckout",initiate_checkout:"InitiateCheckout"},c={addtocart:"AddToCart",add_to_cart:"AddToCart",lead:"SubmitForm",form_submit:"SubmitForm",viewcontent:"ViewContent",view_content:"ViewContent",search:"Search",subscribe:"Subscribe",contact:"Contact",completeregistration:"CompleteRegistration",complete_registration:"CompleteRegistration",initiatecheckout:"InitiateCheckout",initiate_checkout:"InitiateCheckout"},d={addtocart:"add_to_cart",add_to_cart:"add_to_cart",lead:"generate_lead",form_submit:"generate_lead",viewcontent:"view_item",view_content:"view_item",search:"search",subscribe:"subscribe",contact:"contact",completeregistration:"sign_up",complete_registration:"sign_up",initiatecheckout:"begin_checkout",initiate_checkout:"begin_checkout"};if(window.fbq){let r=i[n];r?window.fbq("track",r,e):window.fbq("trackCustom",t,e)}if(window.ttq){let r=c[n]||t;window.ttq.track(r,e)}if(typeof window.gtag=="function"&&g){let r=d[n]||t;window.gtag("event",r,{send_to:g,...e})}}function At(){try{return v==="local"?localStorage:sessionStorage}catch{return null}}function V(t){let e=At();if(!e)return null;try{let n=P+t,i=e.getItem(n);if(!i&&v==="session")try{i=localStorage.getItem(n)}catch{}return i}catch{return null}}function q(t,e){let n=At();if(n)try{n.setItem(P+t,e)}catch{}}function Rt(){if(v!=="local"){a("Upgrading storage tier: session -> local");try{let t=[];for(let e=0;e<sessionStorage.length;e++){let n=sessionStorage.key(e);n?.startsWith(P)&&t.push(n)}for(let e of t){let n=sessionStorage.getItem(e);n&&localStorage.setItem(e,n)}for(let e of t)sessionStorage.removeItem(e);v="local",a(`Storage tier upgraded, migrated ${t.length} items`)}catch(t){C(" Storage migration failed:",t)}}}function B(){return crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function be(){try{let t=V(xt),e=V(Z);if(t&&e&&Date.now()-parseInt(e,10)<ne)return q(Z,Date.now().toString()),t;let n=B();return q(xt,n),q(Z,Date.now().toString()),n}catch{return B()}}function ve(){let t=new URLSearchParams(window.location.search),e={};return["source","medium","campaign","content","term"].forEach(n=>{let i=t.get(`utm_${n}`);i&&(e[`utm_${n}`]=i)}),e}function ke(){try{let t=V(It);if(t){T=JSON.parse(t),a("Loaded attribution:",T);return}let e=ve();Object.keys(e).length>0&&(T=e,q(It,JSON.stringify(e)),a("Captured attribution:",T))}catch{}}function _e(){try{y=V(Ct)}catch{}}function dt(){try{let t=localStorage.getItem(P+tt);if(t)return t;let e=B();return localStorage.setItem(P+tt,e),a("Created persistent visitor ID:",e.substring(0,8)+"..."),e}catch{return a("localStorage unavailable, using session ID as fallback"),O||B()}}function xe(){try{f=localStorage.getItem(P+tt),f&&a("Loaded visitor ID:",f.substring(0,8)+"...")}catch{}}function Ie(){try{let t=localStorage.getItem($);if(t){let e=JSON.parse(t);if(e.expiresAt&&Date.now()>e.expiresAt){a("Consent expired - clearing stored consent"),localStorage.removeItem($),u=null;return}if(e.expiresAt){let n=e.expiresAt-Date.now();n>0&&n<ee&&(a("Consent nearing expiration - will prompt for refresh"),window._balanceConsentNeedsRefresh=!0)}u=e.preferences||null,a("Loaded consent:",u)}}catch{}}function Dt(t){let e=u;u=t;try{let i={preferences:t,method:"explicit",version:1,expiresAt:Date.now()+te};localStorage.setItem($,JSON.stringify(i)),a("Consent saved with TTL:",t),window._balanceConsentNeedsRefresh=!1}catch(i){C(" Could not save consent:",i)}t.analytics===!0&&(Rt(),f||(f=dt()));let n=x({event_name:"consent_updated",metadata:{consent_preferences:t,consent_method:"explicit",previous_consent:e||void 0}});I(n);try{window.dispatchEvent(new CustomEvent("artistPixel:consent:updated",{detail:t})),a("DOM event artistPixel:consent:updated dispatched")}catch{}M&&Lt(t.marketing===!0)}function Ce(){return u}function Se(t){return u?.[t]===!0}function Pe(t){for(let[e,n]of Object.entries(t))try{let i=Mt(e);et[i]=n}catch{et[e]=n}a("Registered",Object.keys(t).length,"links for tracking enrichment")}function Mt(t){try{let e=new URL(t);return`${e.protocol}//${e.host}${e.pathname}${e.search}`}catch{return t}}function Ee(t){let e=Mt(t);return et[e]||null}async function Te(t){let e=t.toLowerCase().trim(),i=new TextEncoder().encode(e),c=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(c)).map(r=>r.toString(16).padStart(2,"0")).join("")}function x(t){let e=Wt(),n={artist_id:W,fan_session_id:O,visitor_id:f||dt(),fan_id_hash:y||void 0,timestamp:new Date().toISOString(),source_url:window.location.href,referrer_url:document.referrer||void 0,user_agent:navigator.userAgent,device_type:e.device_type,browser:e.browser,os:e.os,tracking_source:z,...t,...T};return Y&&!t.projectId&&(n.projectId=Y),n}function I(t){b.push(t),a("Event queued:",t.event_name,"(queue:",b.length,")"),b.length>=10&&F()}async function F(){if(b.length===0)return;let t=[...b];b=[],a("Flushing",t.length,"events to",E);try{let e=await fetch(E,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t}),keepalive:!0});if(!e.ok)throw new Error(`HTTP ${e.status}`);a("Events sent successfully")}catch(e){if(C(" Failed to send events, trying fallback:",e),E!==Pt&&!J)try{if((await fetch(Pt,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t}),keepalive:!0})).ok){a("Events sent via fallback (no geo)");return}}catch(n){C(" Fallback also failed:",n)}b.length<50&&b.push(...t)}}function Le(){nt&&clearInterval(nt),nt=window.setInterval(()=>{b.length>0&&F()},5e3)}function lt(){A||(at=Date.now()),A=Date.now(),U=!0,a("Active time tracking started/resumed")}function Ot(){A&&U&&(it+=Date.now()-A),U=!1,a("Active time tracking paused, accumulated:",it,"ms")}function Ut(){let t=it;return U&&A&&(t+=Date.now()-A),t}function Ae(){Et=Date.now(),j&&(j=!1,lt(),a("User returned from idle"))}function Re(){if(document.visibilityState==="hidden"){a("Skipping heartbeat - tab hidden");return}if(Date.now()-Et>ce){j||(j=!0,Ot(),a("User idle - pausing heartbeat"));return}let t=Ut(),e=Math.round(t/1e3),n=x({event_name:"engagement_heartbeat",metadata:{time_on_page_seconds:e,time_on_page_ms:t,heartbeat_interval_ms:X,is_active:U&&!j}});I(n),ot++,a("Heartbeat sent:",e,"seconds active")}function ut(){if(!ht){a('Heartbeat disabled via data-heartbeat="false"');return}L&&clearInterval(L),lt(),L=window.setInterval(()=>{Re()},X),a("Heartbeat started with interval:",X,"ms")}function gt(){if(!rt){if(rt=!0,L&&(clearInterval(L),L=null),ht){let t=at?Date.now()-at:0,e=Ut(),n=x({event_name:"engagement_summary",metadata:{total_time_ms:t,active_time_ms:e,heartbeat_samples:ot,page_path:window.location.pathname}});if(navigator.sendBeacon&&E){let i=JSON.stringify({events:[n]});navigator.sendBeacon(E,i),a("Engagement summary sent via sendBeacon:",Math.round(e/1e3),"seconds active")}else I(n),a("Engagement summary enqueued:",Math.round(e/1e3),"seconds active")}ot=0}}function N(t={}){let e=t.url||window.location.href;if(ie(e)){a("Page excluded from tracking:",e);return}let n=x({event_name:"pageview",page_title:t.title||document.title,source_url:e});I(n),we()}function ft(t,e={}){let n=x({event_name:"custom",metadata:{event_type:t,...e}});I(n),ye(t,e)}async function jt(t,e={}){try{if(u&&u.analytics===!1){a("Identify skipped - user declined analytics consent");return}y=await Te(t),u?.analytics===!0&&Rt(),q(Ct,y);let n=t.split("@"),i=n[0].charAt(0)+"***@"+(n[1]||"");a("Fan identified:",{name:e.name||"(no name)",email:i,hash:y.substring(0,16)+"...",traits:e,storageTier:v});let c=x({event_name:"identify",fan_id_hash:y,metadata:{email_sha256:y,email_display:i,traits:e,consent_preferences:u||void 0,storage_tier:v}});I(c)}catch(n){C(" Failed to identify:",n)}}function qt(t,e="USD",n={}){let i=x({event_name:"purchase",metadata:{revenue:t,currency:e,...n}});I(i),he(t,e,n)}function Ft(){z=Zt(),a("Tracking source detected:",z),Ie(),u?.analytics===!0?(v="local",a("Storage tier: local (analytics consent granted)")):(v="session",a("Storage tier: session (privacy by default)")),O=be(),_e(),xe(),f||(f=dt()),u||a(Q?"Consent UI enabled, waiting for explicit user consent (Tier 0 mode)":"No consent - operating in privacy-first mode (session storage only, limited tracking)"),M&&u?.marketing===!0?(a("[Platform] Marketing consent already granted, initializing platform pixels"),Lt(!0)):M&&a("[Platform] Platform pixels configured:",{meta:R||"(none)",tiktok:S||"(none)",googleAds:g||"(none)"}),ke(),Le(),a("Initialized",{artistId:W,projectId:Y||"(none - will track to all projects)",rawProjectId:K||"(none)",sessionId:O,visitorId:f?f.substring(0,8)+"...":null,fanIdHash:y,consent:u,storageTier:v,trackingSource:z,useEmulator:J,endpoint:E}),u?.analytics===!0?(window._balanceInitialPageviewFired=!0,N(),ut(),a("Full tracking enabled (user consented)")):Q?a("Tracking dormant - waiting for explicit consent via ConsentManager"):(window._balanceInitialPageviewFired=!0,N(),ut(),a("Privacy-first tracking enabled (session-scoped, visitor_id for deduplication)")),["mousemove","keydown","scroll","touchstart"].forEach(r=>{document.addEventListener(r,Ae,{passive:!0})});let t=window.location.hostname;function e(r){try{let o=new URL(r).hostname.toLowerCase();return o.includes("spotify")?"spotify":o.includes("apple")||o.includes("music.apple")?"apple_music":o.includes("youtube")||o.includes("youtu.be")?"youtube":o.includes("soundcloud")?"soundcloud":o.includes("tidal")?"tidal":o.includes("deezer")?"deezer":o.includes("amazon")||o.includes("music.amazon")?"amazon_music":o.includes("bandcamp")?"bandcamp":o.includes("lnk.to")||o.includes("linkfire")?"linkfire":o.includes("linktr.ee")?"linktree":o.includes("shop")||o.includes("store")||o.includes("merch")?"shop":o.includes("ticketmaster")||o.includes("eventbrite")||o.includes("dice.fm")?"tickets":o.includes("instagram")?"instagram":o.includes("twitter")||o.includes("x.com")?"twitter":o.includes("tiktok")?"tiktok":o.includes("facebook")?"facebook":"external"}catch{return"external"}}function n(r){try{return new URL(r,window.location.origin).hostname!==t}catch{return!1}}function i(r,o){let l=e(r),k=Ee(r),Vt=k?.title||o?.textContent?.trim().substring(0,100)||"",Bt=k?.id||o?.id||o?.getAttribute("data-link-id")||void 0,Gt=k?.category;a("External link clicked:",{url:r,platform:l,linkText:Vt,linkId:Bt,fromRegistry:!!k}),ft("page_link_click",{link_url:r,link_text:Vt,link_id:Bt,platform:l,link_type:"external",...Gt&&{link_category:Gt},...k&&Object.fromEntries(Object.entries(k).filter(([pt])=>!["title","id","category"].includes(pt)).map(([pt,De])=>[`link_${pt}`,De]))})}let c=window.open;if(window.open=function(r,o,l){if(r){let k=r.toString();n(k)&&i(k)}return c.call(window,r,o,l)},a("window.open interception enabled (always on)"),s?.dataset.autoTrackLinks==="true"&&(document.addEventListener("click",r=>{let l=r.target.closest("a");if(l&&l.href&&n(l.href)){if(_t&&(St(l.href)||l.hasAttribute("download")))return;i(l.href,l)}},{capture:!0,passive:!0}),a("External link click listener enabled (opt-in)")),_t&&(document.addEventListener("click",r=>{let l=r.target.closest("a");l?.href&&(St(l.href)||l.hasAttribute("download"))&&re(l.href,l)},{capture:!0,passive:!0}),a("File download tracking enabled")),Qt){let r=window.location.href;window.addEventListener("hashchange",()=>{let o=window.location.href;o!==r&&(r=o,setTimeout(()=>{N({title:document.title,url:o})},0))}),a("Hash routing tracking enabled")}document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(Ot(),gt(),F()):(lt(),rt=!1)}),window.addEventListener("pagehide",()=>{gt(),F()}),window.addEventListener("beforeunload",()=>{gt(),F()})}if(window.balance?._version&&window.balance._version!==w){console.warn(`[artistPixel] Version conflict: ${window.balance._version} already loaded, skipping ${w}`);return}let mt=window.balance?.q||[];function Nt(){if(mt.length>0){a("Processing",mt.length,"queued commands");for(let t of mt){let[e,...n]=t;switch(e){case"track":ft(n[0],n[1]);break;case"identify":jt(n[0],n[1]);break;case"page":N(n[0]);break;case"purchase":qt(n[0],n[1],n[2]);break;case"setConsent":Dt(n[0]);break;default:a("Unknown queued command:",e)}}}}let zt={track:ft,identify:jt,page:N,purchase:qt,getSessionId:()=>O,getVisitorId:()=>f,getFanIdHash:()=>y,getAttribution:()=>T,setConsent:Dt,getConsent:Ce,hasConsent:Se,registerLinks:Pe,_version:w};window.artistPixel=zt,window.balance=zt;function $t(){Q&&!u&&new le({style:Yt,primaryColor:Jt,position:Xt})}let Ht=window.requestIdleCallback||(t=>setTimeout(t,1));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Ft(),Nt(),Ht(()=>$t())}):(Ft(),Nt(),Ht(()=>$t())),a("Pixel script loaded")})();})();
|