@hifilabs/pixel 0.8.0 → 0.9.1
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 +259 -11
- package/dist/browser.min.js +5 -5
- package/dist/index.js +9 -0
- package/dist/index.mjs +9 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -8,7 +8,7 @@ var BalancePixel = (() => {
|
|
|
8
8
|
|
|
9
9
|
// src/browser.ts
|
|
10
10
|
(function() {
|
|
11
|
-
const PIXEL_VERSION = "0.
|
|
11
|
+
const PIXEL_VERSION = "0.9.1";
|
|
12
12
|
function parseUserAgent(ua) {
|
|
13
13
|
let device_type = "desktop";
|
|
14
14
|
if (/ipad|tablet|android(?!.*mobile)/i.test(ua))
|
|
@@ -66,7 +66,7 @@ var BalancePixel = (() => {
|
|
|
66
66
|
}
|
|
67
67
|
const useEmulator = currentScript?.dataset.emulator === "true";
|
|
68
68
|
const debug = currentScript?.dataset.debug === "true";
|
|
69
|
-
const heartbeatInterval = parseInt(currentScript?.dataset.heartbeatInterval || "
|
|
69
|
+
const heartbeatInterval = parseInt(currentScript?.dataset.heartbeatInterval || "120000", 10);
|
|
70
70
|
const heartbeatEnabled = currentScript?.dataset.heartbeat !== "false";
|
|
71
71
|
const explicitSource = currentScript?.dataset.source;
|
|
72
72
|
const customEndpoint = currentScript?.dataset.endpoint;
|
|
@@ -74,6 +74,9 @@ var BalancePixel = (() => {
|
|
|
74
74
|
const consentStyle = currentScript?.dataset.consentStyle || "brutalist";
|
|
75
75
|
const consentPrimaryColor = currentScript?.dataset.primaryColor;
|
|
76
76
|
const consentBannerPosition = currentScript?.dataset.bannerPosition || "bottom";
|
|
77
|
+
const excludePatterns = currentScript?.dataset.excludePages?.split(",").filter(Boolean) || [];
|
|
78
|
+
const trackFileDownloads = currentScript?.dataset.trackFileDownloads === "true";
|
|
79
|
+
const hashRoutingEnabled = currentScript?.dataset.hashRouting === "true";
|
|
77
80
|
function detectTrackingSource() {
|
|
78
81
|
if (explicitSource)
|
|
79
82
|
return explicitSource;
|
|
@@ -99,7 +102,88 @@ var BalancePixel = (() => {
|
|
|
99
102
|
const CONSENT_REFRESH_THRESHOLD = 30 * 24 * 60 * 60 * 1e3;
|
|
100
103
|
const SESSION_DURATION = 60 * 60 * 1e3;
|
|
101
104
|
const STORAGE_PREFIX = "balance_";
|
|
102
|
-
|
|
105
|
+
function globToRegex(pattern) {
|
|
106
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
107
|
+
return new RegExp("^" + escaped + "$");
|
|
108
|
+
}
|
|
109
|
+
function isExcludedPage(url) {
|
|
110
|
+
if (excludePatterns.length === 0)
|
|
111
|
+
return false;
|
|
112
|
+
try {
|
|
113
|
+
const pathname = new URL(url, window.location.origin).pathname;
|
|
114
|
+
return excludePatterns.some((pattern) => {
|
|
115
|
+
const regex = globToRegex(pattern);
|
|
116
|
+
return regex.test(pathname);
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const DOWNLOAD_EXTENSIONS = [
|
|
123
|
+
".pdf",
|
|
124
|
+
".zip",
|
|
125
|
+
".tar",
|
|
126
|
+
".gz",
|
|
127
|
+
".rar",
|
|
128
|
+
".7z",
|
|
129
|
+
".doc",
|
|
130
|
+
".docx",
|
|
131
|
+
".xls",
|
|
132
|
+
".xlsx",
|
|
133
|
+
".ppt",
|
|
134
|
+
".pptx",
|
|
135
|
+
".mp3",
|
|
136
|
+
".wav",
|
|
137
|
+
".flac",
|
|
138
|
+
".aac",
|
|
139
|
+
".ogg",
|
|
140
|
+
".mp4",
|
|
141
|
+
".mov",
|
|
142
|
+
".avi",
|
|
143
|
+
".mkv",
|
|
144
|
+
".webm",
|
|
145
|
+
".exe",
|
|
146
|
+
".dmg",
|
|
147
|
+
".pkg",
|
|
148
|
+
".deb",
|
|
149
|
+
".rpm",
|
|
150
|
+
".csv",
|
|
151
|
+
".json",
|
|
152
|
+
".xml",
|
|
153
|
+
".txt"
|
|
154
|
+
];
|
|
155
|
+
function isFileDownload(url) {
|
|
156
|
+
try {
|
|
157
|
+
const pathname = new URL(url, window.location.origin).pathname.toLowerCase();
|
|
158
|
+
return DOWNLOAD_EXTENSIONS.some((ext) => pathname.endsWith(ext));
|
|
159
|
+
} catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function trackFileDownload(url, element) {
|
|
164
|
+
try {
|
|
165
|
+
const pathname = new URL(url, window.location.origin).pathname;
|
|
166
|
+
const fileName = pathname.split("/").pop() || "unknown";
|
|
167
|
+
const fileExtension = fileName.includes(".") ? fileName.split(".").pop() : "unknown";
|
|
168
|
+
log("File download tracked:", { url, fileName, fileExtension });
|
|
169
|
+
const event = buildEvent({
|
|
170
|
+
event_name: "custom",
|
|
171
|
+
metadata: {
|
|
172
|
+
event_type: "file_download",
|
|
173
|
+
file_url: url,
|
|
174
|
+
file_name: fileName,
|
|
175
|
+
file_extension: fileExtension,
|
|
176
|
+
link_text: element?.textContent?.trim().substring(0, 100) || ""
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
enqueueEvent(event);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
logError("Failed to track file download:", e);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const PIXEL_PROXY_URL = "https://balance-pixel-proxy.hifilabs.workers.dev";
|
|
185
|
+
const FIREBASE_DIRECT_URL = "https://us-central1-artist-os-distro.cloudfunctions.net/ingestEvents";
|
|
186
|
+
const API_ENDPOINT = customEndpoint ? customEndpoint : useEmulator ? `http://localhost:5001/artist-os-distro/us-central1/ingestEvents` : PIXEL_PROXY_URL;
|
|
103
187
|
let sessionId = null;
|
|
104
188
|
let visitorId = null;
|
|
105
189
|
let fanIdHash = null;
|
|
@@ -113,6 +197,8 @@ var BalancePixel = (() => {
|
|
|
113
197
|
let activeTime = 0;
|
|
114
198
|
let lastActiveTimestamp = 0;
|
|
115
199
|
let isPageVisible = true;
|
|
200
|
+
let heartbeatCount = 0;
|
|
201
|
+
let summarySent = false;
|
|
116
202
|
const IDLE_TIMEOUT = 2 * 60 * 1e3;
|
|
117
203
|
let lastActivityTime = Date.now();
|
|
118
204
|
let isIdle = false;
|
|
@@ -582,7 +668,23 @@ var BalancePixel = (() => {
|
|
|
582
668
|
}
|
|
583
669
|
log("Events sent successfully");
|
|
584
670
|
} catch (error) {
|
|
585
|
-
logError(" Failed to send events:", error);
|
|
671
|
+
logError(" Failed to send events, trying fallback:", error);
|
|
672
|
+
if (API_ENDPOINT !== FIREBASE_DIRECT_URL && !useEmulator) {
|
|
673
|
+
try {
|
|
674
|
+
const fallbackResponse = await fetch(FIREBASE_DIRECT_URL, {
|
|
675
|
+
method: "POST",
|
|
676
|
+
headers: { "Content-Type": "application/json" },
|
|
677
|
+
body: JSON.stringify({ events }),
|
|
678
|
+
keepalive: true
|
|
679
|
+
});
|
|
680
|
+
if (fallbackResponse.ok) {
|
|
681
|
+
log("Events sent via fallback (no geo)");
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
} catch (fallbackError) {
|
|
685
|
+
logError(" Fallback also failed:", fallbackError);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
586
688
|
if (eventQueue.length < 50) {
|
|
587
689
|
eventQueue.push(...events);
|
|
588
690
|
}
|
|
@@ -651,6 +753,7 @@ var BalancePixel = (() => {
|
|
|
651
753
|
}
|
|
652
754
|
});
|
|
653
755
|
enqueueEvent(event);
|
|
756
|
+
heartbeatCount++;
|
|
654
757
|
log("Heartbeat sent:", timeOnPageSeconds, "seconds active");
|
|
655
758
|
}
|
|
656
759
|
function startHeartbeat() {
|
|
@@ -667,20 +770,46 @@ var BalancePixel = (() => {
|
|
|
667
770
|
log("Heartbeat started with interval:", heartbeatInterval, "ms");
|
|
668
771
|
}
|
|
669
772
|
function stopHeartbeat() {
|
|
773
|
+
if (summarySent)
|
|
774
|
+
return;
|
|
775
|
+
summarySent = true;
|
|
670
776
|
if (heartbeatTimer) {
|
|
671
777
|
clearInterval(heartbeatTimer);
|
|
672
778
|
heartbeatTimer = null;
|
|
673
779
|
}
|
|
674
780
|
if (heartbeatEnabled) {
|
|
675
|
-
|
|
676
|
-
|
|
781
|
+
const totalTimeMs = pageStartTime ? Date.now() - pageStartTime : 0;
|
|
782
|
+
const activeTimeMs = getCumulativeActiveTime();
|
|
783
|
+
const event = buildEvent({
|
|
784
|
+
event_name: "engagement_summary",
|
|
785
|
+
metadata: {
|
|
786
|
+
total_time_ms: totalTimeMs,
|
|
787
|
+
active_time_ms: activeTimeMs,
|
|
788
|
+
heartbeat_samples: heartbeatCount,
|
|
789
|
+
page_path: window.location.pathname
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
if (navigator.sendBeacon && API_ENDPOINT) {
|
|
793
|
+
const payload = JSON.stringify({ events: [event] });
|
|
794
|
+
navigator.sendBeacon(API_ENDPOINT, payload);
|
|
795
|
+
log("Engagement summary sent via sendBeacon:", Math.round(activeTimeMs / 1e3), "seconds active");
|
|
796
|
+
} else {
|
|
797
|
+
enqueueEvent(event);
|
|
798
|
+
log("Engagement summary enqueued:", Math.round(activeTimeMs / 1e3), "seconds active");
|
|
799
|
+
}
|
|
677
800
|
}
|
|
801
|
+
heartbeatCount = 0;
|
|
678
802
|
}
|
|
679
803
|
function trackPageView(options = {}) {
|
|
804
|
+
const pageUrl = options.url || window.location.href;
|
|
805
|
+
if (isExcludedPage(pageUrl)) {
|
|
806
|
+
log("Page excluded from tracking:", pageUrl);
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
680
809
|
const event = buildEvent({
|
|
681
810
|
event_name: "pageview",
|
|
682
811
|
page_title: options.title || document.title,
|
|
683
|
-
source_url:
|
|
812
|
+
source_url: pageUrl
|
|
684
813
|
});
|
|
685
814
|
enqueueEvent(event);
|
|
686
815
|
}
|
|
@@ -798,18 +927,137 @@ var BalancePixel = (() => {
|
|
|
798
927
|
["mousemove", "keydown", "scroll", "touchstart"].forEach((eventType) => {
|
|
799
928
|
document.addEventListener(eventType, resetIdleTimer, { passive: true });
|
|
800
929
|
});
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
930
|
+
const currentHost = window.location.hostname;
|
|
931
|
+
function detectPlatform(url) {
|
|
932
|
+
try {
|
|
933
|
+
const hostname = new URL(url).hostname.toLowerCase();
|
|
934
|
+
if (hostname.includes("spotify"))
|
|
935
|
+
return "spotify";
|
|
936
|
+
if (hostname.includes("apple") || hostname.includes("music.apple"))
|
|
937
|
+
return "apple_music";
|
|
938
|
+
if (hostname.includes("youtube") || hostname.includes("youtu.be"))
|
|
939
|
+
return "youtube";
|
|
940
|
+
if (hostname.includes("soundcloud"))
|
|
941
|
+
return "soundcloud";
|
|
942
|
+
if (hostname.includes("tidal"))
|
|
943
|
+
return "tidal";
|
|
944
|
+
if (hostname.includes("deezer"))
|
|
945
|
+
return "deezer";
|
|
946
|
+
if (hostname.includes("amazon") || hostname.includes("music.amazon"))
|
|
947
|
+
return "amazon_music";
|
|
948
|
+
if (hostname.includes("bandcamp"))
|
|
949
|
+
return "bandcamp";
|
|
950
|
+
if (hostname.includes("lnk.to") || hostname.includes("linkfire"))
|
|
951
|
+
return "linkfire";
|
|
952
|
+
if (hostname.includes("linktr.ee"))
|
|
953
|
+
return "linktree";
|
|
954
|
+
if (hostname.includes("shop") || hostname.includes("store") || hostname.includes("merch"))
|
|
955
|
+
return "shop";
|
|
956
|
+
if (hostname.includes("ticketmaster") || hostname.includes("eventbrite") || hostname.includes("dice.fm"))
|
|
957
|
+
return "tickets";
|
|
958
|
+
if (hostname.includes("instagram"))
|
|
959
|
+
return "instagram";
|
|
960
|
+
if (hostname.includes("twitter") || hostname.includes("x.com"))
|
|
961
|
+
return "twitter";
|
|
962
|
+
if (hostname.includes("tiktok"))
|
|
963
|
+
return "tiktok";
|
|
964
|
+
if (hostname.includes("facebook"))
|
|
965
|
+
return "facebook";
|
|
966
|
+
return "external";
|
|
967
|
+
} catch {
|
|
968
|
+
return "external";
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
function isExternalLink(url) {
|
|
972
|
+
try {
|
|
973
|
+
const linkHost = new URL(url, window.location.origin).hostname;
|
|
974
|
+
return linkHost !== currentHost;
|
|
975
|
+
} catch {
|
|
976
|
+
return false;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
function trackExternalClick(url, element) {
|
|
980
|
+
const platform = detectPlatform(url);
|
|
981
|
+
const linkText = element?.textContent?.trim().substring(0, 100) || "";
|
|
982
|
+
const linkId = element?.id || element?.getAttribute("data-link-id") || void 0;
|
|
983
|
+
log("External link clicked:", { url, platform, linkText });
|
|
984
|
+
track("page_link_click", {
|
|
985
|
+
link_url: url,
|
|
986
|
+
link_text: linkText,
|
|
987
|
+
link_id: linkId,
|
|
988
|
+
platform,
|
|
989
|
+
link_type: "external"
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
const originalWindowOpen = window.open;
|
|
993
|
+
window.open = function(url, target, features) {
|
|
994
|
+
if (url) {
|
|
995
|
+
const urlString = url.toString();
|
|
996
|
+
if (isExternalLink(urlString)) {
|
|
997
|
+
trackExternalClick(urlString);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return originalWindowOpen.call(window, url, target, features);
|
|
1001
|
+
};
|
|
1002
|
+
log("window.open interception enabled (always on)");
|
|
1003
|
+
const autoTrackLinks = currentScript?.dataset.autoTrackLinks === "true";
|
|
1004
|
+
if (autoTrackLinks) {
|
|
1005
|
+
document.addEventListener("click", (e) => {
|
|
1006
|
+
const target = e.target;
|
|
1007
|
+
const anchor = target.closest("a");
|
|
1008
|
+
if (anchor && anchor.href && isExternalLink(anchor.href)) {
|
|
1009
|
+
if (trackFileDownloads && (isFileDownload(anchor.href) || anchor.hasAttribute("download"))) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
trackExternalClick(anchor.href, anchor);
|
|
1013
|
+
}
|
|
1014
|
+
}, { capture: true, passive: true });
|
|
1015
|
+
log("External link click listener enabled (opt-in)");
|
|
1016
|
+
}
|
|
1017
|
+
if (trackFileDownloads) {
|
|
1018
|
+
document.addEventListener("click", (e) => {
|
|
1019
|
+
const target = e.target;
|
|
1020
|
+
const anchor = target.closest("a");
|
|
1021
|
+
if (anchor?.href && (isFileDownload(anchor.href) || anchor.hasAttribute("download"))) {
|
|
1022
|
+
trackFileDownload(anchor.href, anchor);
|
|
1023
|
+
}
|
|
1024
|
+
}, { capture: true, passive: true });
|
|
1025
|
+
log("File download tracking enabled");
|
|
1026
|
+
}
|
|
1027
|
+
if (hashRoutingEnabled) {
|
|
1028
|
+
let lastUrl = window.location.href;
|
|
1029
|
+
window.addEventListener("hashchange", () => {
|
|
1030
|
+
const newUrl = window.location.href;
|
|
1031
|
+
if (newUrl !== lastUrl) {
|
|
1032
|
+
lastUrl = newUrl;
|
|
1033
|
+
setTimeout(() => {
|
|
1034
|
+
trackPageView({
|
|
1035
|
+
title: document.title,
|
|
1036
|
+
url: newUrl
|
|
1037
|
+
});
|
|
1038
|
+
}, 0);
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
log("Hash routing tracking enabled");
|
|
1042
|
+
}
|
|
805
1043
|
document.addEventListener("visibilitychange", () => {
|
|
806
1044
|
if (document.visibilityState === "hidden") {
|
|
807
1045
|
pauseActiveTimeTracking();
|
|
1046
|
+
stopHeartbeat();
|
|
808
1047
|
flush();
|
|
809
1048
|
} else {
|
|
810
1049
|
startActiveTimeTracking();
|
|
1050
|
+
summarySent = false;
|
|
811
1051
|
}
|
|
812
1052
|
});
|
|
1053
|
+
window.addEventListener("pagehide", () => {
|
|
1054
|
+
stopHeartbeat();
|
|
1055
|
+
flush();
|
|
1056
|
+
});
|
|
1057
|
+
window.addEventListener("beforeunload", () => {
|
|
1058
|
+
stopHeartbeat();
|
|
1059
|
+
flush();
|
|
1060
|
+
});
|
|
813
1061
|
}
|
|
814
1062
|
if (window.balance?._version && window.balance._version !== PIXEL_VERSION) {
|
|
815
1063
|
console.warn(
|
package/dist/browser.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var BalancePixel=(()=>{var
|
|
1
|
+
var BalancePixel=(()=>{var at=Object.defineProperty;var rt=(g,p,u)=>p in g?at(g,p,{enumerable:!0,configurable:!0,writable:!0,value:u}):g[p]=u;var M=(g,p,u)=>(rt(g,typeof p!="symbol"?p+"":p,u),u);(function(){let g="0.9.1";function p(e){let t="desktop";/ipad|tablet|android(?!.*mobile)/i.test(e)?t="tablet":/mobile|iphone|android.*mobile|blackberry|iemobile/i.test(e)&&(t="mobile");let n="Unknown";/edg/i.test(e)?n="Edge":/opr|opera/i.test(e)?n="Opera":/firefox/i.test(e)?n="Firefox":/chrome/i.test(e)?n="Chrome":/safari/i.test(e)&&(n="Safari");let o="Unknown";return/iphone|ipad/i.test(e)?o="iOS":/android/i.test(e)?o="Android":/windows/i.test(e)?o="Windows":/mac os/i.test(e)?o="macOS":/linux/i.test(e)?o="Linux":/cros/i.test(e)&&(o="ChromeOS"),{device_type:t,browser:n,os:o}}let u=null;function Te(){if(!u)try{u=p(navigator.userAgent)}catch{u={device_type:"desktop",browser:"Unknown",os:"Unknown"}}return u}let l=document.currentScript,F=l?.dataset.artistId,H=l?.dataset.projectId,z=H?Le(H):void 0;function Le(e){return!e||e.startsWith("release_")||e.startsWith("merch_")||e.startsWith("link_")||e.startsWith("custom_")?e:`custom_${e}`}let B=l?.dataset.emulator==="true",oe=l?.dataset.debug==="true",j=parseInt(l?.dataset.heartbeatInterval||"120000",10),ae=l?.dataset.heartbeat!=="false",re=l?.dataset.source,se=l?.dataset.endpoint,$=l?.dataset.consentUi==="true",De=l?.dataset.consentStyle||"brutalist",Pe=l?.dataset.primaryColor,Re=l?.dataset.bannerPosition||"bottom",ce=l?.dataset.excludePages?.split(",").filter(Boolean)||[],le=l?.dataset.trackFileDownloads==="true",Oe=l?.dataset.hashRouting==="true";function Ae(){if(re)return re;let e=typeof window.dataLayer<"u"&&Array.isArray(window.dataLayer),t=typeof window.gtag=="function";return e&&t?"gtm":"pixel"}let O="pixel";if(!F){v(" Error: data-artist-id attribute is required");return}let de="session_id",W="session_timestamp",ue="attribution",fe="fan_id_hash",q="visitor_id",A="balance_consent",Ne=365*24*60*60*1e3,Ue=30*24*60*60*1e3,Me=60*60*1e3,x="balance_";function Fe(e){let t=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp("^"+t+"$")}function He(e){if(ce.length===0)return!1;try{let t=new URL(e,window.location.origin).pathname;return ce.some(n=>Fe(n).test(t))}catch{return!1}}let ze=[".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 ge(e){try{let t=new URL(e,window.location.origin).pathname.toLowerCase();return ze.some(n=>t.endsWith(n))}catch{return!1}}function Be(e,t){try{let o=new URL(e,window.location.origin).pathname.split("/").pop()||"unknown",f=o.includes(".")?o.split(".").pop():"unknown";i("File download tracked:",{url:e,fileName:o,fileExtension:f});let P=w({event_name:"custom",metadata:{event_type:"file_download",file_url:e,file_name:o,file_extension:f,link_text:t?.textContent?.trim().substring(0,100)||""}});y(P)}catch(n){v("Failed to track file download:",n)}}let je="https://balance-pixel-proxy.hifilabs.workers.dev",pe="https://us-central1-artist-os-distro.cloudfunctions.net/ingestEvents",k=se||(B?"http://localhost:5001/artist-os-distro/us-central1/ingestEvents":je),N=null,d=null,m=null,s=null,_={},h=[],V=null,b="session",I=null,K=0,Y=0,S=0,E=!0,J=0,X=!1,$e=2*60*1e3,me=Date.now(),C=!1,We=!oe,i=(...e)=>{oe&&console.log("[BLN]",...e)},v=(...e)=>{We||console.error("[BLN]",...e)},G={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 BalancePixel=(()=>{var ze=Object.defineProperty;var Ve=(l,d,c)=>d in l?ze(l,
|
|
|
83
83
|
}
|
|
84
84
|
.btn.accept { background: #fff; color: #000; border-color: #fff; }
|
|
85
85
|
.btn:hover { opacity: 0.8; }
|
|
86
|
-
`};class
|
|
86
|
+
`};class qe{constructor(t){M(this,"container",null);M(this,"shadow",null);M(this,"config");if(this.config=t,this.hasStoredConsent()){i("ConsentManager: Consent already exists, not showing banner");return}this.container=document.createElement("div"),this.container.id="balance-consent-manager",this.shadow=this.container.attachShadow({mode:"closed"}),this.render(),document.body.appendChild(this.container),i("ConsentManager: Banner rendered")}hasStoredConsent(){try{return window._balanceConsentNeedsRefresh?!1:localStorage.getItem(A)!==null}catch{return!1}}render(){if(!this.shadow)return;let t=this.config.style||"brutalist",n=G.base,o=G[t]||G.brutalist,f=this.config.position==="top"?"top: 0;":"bottom: 0;",P=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
|
-
:host { ${
|
|
89
|
+
:host { ${f} }
|
|
90
90
|
${o}
|
|
91
|
-
${
|
|
91
|
+
${P}
|
|
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 BalancePixel=(()=>{var ze=Object.defineProperty;var Ve=(l,d,c)=>d in l?ze(l,
|
|
|
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(t){window.balance?.setConsent&&window.balance.setConsent({analytics:t,marketing:t,personalization:t,timestamp:new Date().toISOString()}),t&&!window._balanceInitialPageviewFired&&(window._balanceInitialPageviewFired=!0,window.balance?.page&&window.balance.page(),W(),r("Initial pageview fired after consent granted")),this.remove()}remove(){this.container&&(this.container.remove(),this.container=null,this.shadow=null,r("ConsentManager: Banner removed"))}}function ne(){try{return g==="local"?localStorage:sessionStorage}catch{return null}}function T(e){let t=ne();if(!t)return null;try{let n=p+e,o=t.getItem(n);if(!o&&g==="session")try{o=localStorage.getItem(n)}catch{}return o}catch{return null}}function S(e,t){let n=ne();if(n)try{n.setItem(p+e,t)}catch{}}function re(){if(g!=="local"){r("Upgrading storage tier: session -> local");try{let e=[];for(let t=0;t<sessionStorage.length;t++){let n=sessionStorage.key(t);n?.startsWith(p)&&e.push(n)}for(let t of e){let n=sessionStorage.getItem(t);n&&localStorage.setItem(t,n)}for(let t of e)sessionStorage.removeItem(t);g="local",r(`Storage tier upgraded, migrated ${e.length} items`)}catch(e){x(" Storage migration failed:",e)}}}function z(){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 De(){try{let e=T(X),t=T(M);if(e&&t&&Date.now()-parseInt(t,10)<_e)return S(M,Date.now().toString()),e;let n=z();return S(X,n),S(M,Date.now().toString()),n}catch{return z()}}function Pe(){let e=new URLSearchParams(window.location.search),t={};return["source","medium","campaign","content","term"].forEach(n=>{let o=e.get(`utm_${n}`);o&&(t[`utm_${n}`]=o)}),t}function Ae(){try{let e=T(Z);if(e){m=JSON.parse(e),r("Loaded attribution:",m);return}let t=Pe();Object.keys(t).length>0&&(m=t,S(Z,JSON.stringify(t)),r("Captured attribution:",m))}catch{}}function Oe(){try{u=T(ee)}catch{}}function oe(){if(!i?.analytics)return null;try{let e=localStorage.getItem(p+F);if(e)return e;let t=z();return localStorage.setItem(p+F,t),r("Created persistent visitor ID:",t.substring(0,8)+"..."),t}catch{return null}}function Ne(){if(!i?.analytics){s=null;return}try{s=localStorage.getItem(p+F),s&&r("Loaded visitor ID:",s.substring(0,8)+"...")}catch{}}function Le(){try{let e=localStorage.getItem(C);if(e){let t=JSON.parse(e);if(t.expiresAt&&Date.now()>t.expiresAt){r("Consent expired - clearing stored consent"),localStorage.removeItem(C),i=null;return}if(t.expiresAt){let n=t.expiresAt-Date.now();n>0&&n<Se&&(r("Consent nearing expiration - will prompt for refresh"),window._balanceConsentNeedsRefresh=!0)}i=t.preferences||null,r("Loaded consent:",i)}}catch{}}function ie(e){let t=i;i=e;try{let o={preferences:e,method:"explicit",version:1,expiresAt:Date.now()+xe};localStorage.setItem(C,JSON.stringify(o)),r("Consent saved with TTL:",e),window._balanceConsentNeedsRefresh=!1}catch(o){x(" Could not save consent:",o)}e.analytics===!0&&(re(),s||(s=oe()));let n=y({event_name:"consent_updated",metadata:{consent_preferences:e,consent_method:"explicit",previous_consent:t||void 0}});v(n);try{window.dispatchEvent(new CustomEvent("balance:consent:updated",{detail:e})),r("DOM event balance:consent:updated dispatched")}catch{}}function Re(){return i}function Ue(e){return i?.[e]===!0}async function Me(e){let t=e.toLowerCase().trim(),o=new TextEncoder().encode(t),_=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(_)).map($e=>$e.toString(16).padStart(2,"0")).join("")}function y(e){let t=be(),n={artist_id:O,fan_session_id:E,visitor_id:s||void 0,fan_id_hash:u||void 0,timestamp:new Date().toISOString(),source_url:window.location.href,referrer_url:document.referrer||void 0,user_agent:navigator.userAgent,device_type:t.device_type,browser:t.browser,os:t.os,tracking_source:k,...e,...m};return L&&!e.projectId&&(n.projectId=L),n}function v(e){f.push(e),r("Event queued:",e.event_name,"(queue:",f.length,")"),f.length>=10&&D()}async function D(){if(f.length===0)return;let e=[...f];f=[],r("Flushing",e.length,"events to",H);try{let t=await fetch(H,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:e}),keepalive:!0});if(!t.ok)throw new Error(`HTTP ${t.status}`);r("Events sent successfully")}catch(t){x(" Failed to send events:",t),f.length<50&&f.push(...e)}}function Fe(){j&&clearInterval(j),j=window.setInterval(()=>{f.length>0&&D()},5e3)}function V(){h||(ke=Date.now()),h=Date.now(),w=!0,r("Active time tracking started/resumed")}function ae(){h&&w&&(B+=Date.now()-h),w=!1,r("Active time tracking paused, accumulated:",B,"ms")}function He(){let e=B;return w&&h&&(e+=Date.now()-h),e}function je(){te=Date.now(),I&&(I=!1,V(),r("User returned from idle"))}function se(){if(document.visibilityState==="hidden"){r("Skipping heartbeat - tab hidden");return}if(Date.now()-te>Ce){I||(I=!0,ae(),r("User idle - pausing heartbeat"));return}let e=He(),t=Math.round(e/1e3),n=y({event_name:"engagement_heartbeat",metadata:{time_on_page_seconds:t,time_on_page_ms:e,heartbeat_interval_ms:R,is_active:w&&!I}});v(n),r("Heartbeat sent:",t,"seconds active")}function W(){if(!J){r('Heartbeat disabled via data-heartbeat="false"');return}b&&clearInterval(b),V(),b=window.setInterval(()=>{se()},R),r("Heartbeat started with interval:",R,"ms")}function Be(){b&&(clearInterval(b),b=null),J&&(se(),r("Heartbeat stopped, final time sent"))}function P(e={}){let t=y({event_name:"pageview",page_title:e.title||document.title,source_url:e.url||window.location.href});v(t)}function ce(e,t={}){let n=y({event_name:"custom",metadata:{event_type:e,...t}});v(n)}async function le(e,t={}){try{if(i&&i.analytics===!1){r("Identify skipped - user declined analytics consent");return}u=await Me(e),i?.analytics===!0&&re(),S(ee,u);let n=e.split("@"),o=n[0].charAt(0)+"***@"+(n[1]||"");r("Fan identified:",{name:t.name||"(no name)",email:o,hash:u.substring(0,16)+"...",traits:t,storageTier:g});let _=y({event_name:"identify",fan_id_hash:u,metadata:{email_sha256:u,email_display:o,traits:t,consent_preferences:i||void 0,storage_tier:g}});v(_)}catch(n){x(" Failed to identify:",n)}}function de(e,t="USD",n={}){let o=y({event_name:"purchase",metadata:{revenue:e,currency:t,...n}});v(o)}function ue(){k=Ie(),r("Tracking source detected:",k),Le(),i?.analytics===!0?(g="local",r("Storage tier: local (analytics consent granted)")):(g="session",r("Storage tier: session (privacy by default)")),E=De(),Oe(),Ne(),i||r(U?"Consent UI enabled, waiting for explicit user consent (Tier 0 mode)":"No consent - operating in privacy-first mode (session storage only, limited tracking)"),i?.analytics&&!s&&(s=oe()),Ae(),Fe(),r("Initialized",{artistId:O,projectId:L||"(none - will track to all projects)",rawProjectId:N||"(none)",sessionId:E,visitorId:s?s.substring(0,8)+"...":null,fanIdHash:u,consent:i,storageTier:g,trackingSource:k,useEmulator:K,endpoint:H}),i?.analytics===!0?(window._balanceInitialPageviewFired=!0,P(),W(),r("Full tracking enabled (user consented)")):U?r("Tracking dormant - waiting for explicit consent via ConsentManager"):(window._balanceInitialPageviewFired=!0,P(),W(),r("Privacy-first tracking enabled (session-scoped, no persistent IDs)")),["mousemove","keydown","scroll","touchstart"].forEach(e=>{document.addEventListener(e,je,{passive:!0})}),window.addEventListener("beforeunload",()=>{Be(),D()}),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(ae(),D()):V()})}if(window.balance?._version&&window.balance._version!==l){console.warn(`[BLN] Version conflict: ${window.balance._version} already loaded, skipping ${l}`);return}let q=window.balance?.q||[];function fe(){if(q.length>0){r("Processing",q.length,"queued commands");for(let e of q){let[t,...n]=e;switch(t){case"track":ce(n[0],n[1]);break;case"identify":le(n[0],n[1]);break;case"page":P(n[0]);break;case"purchase":de(n[0],n[1],n[2]);break;case"setConsent":ie(n[0]);break;default:r("Unknown queued command:",t)}}}}window.balance={track:ce,identify:le,page:P,purchase:de,getSessionId:()=>E,getVisitorId:()=>s,getFanIdHash:()=>u,getAttribution:()=>m,setConsent:ie,getConsent:Re,hasConsent:Ue,_version:l};function ge(){U&&!i&&new Te({style:ye,primaryColor:ve,position:we})}let pe=window.requestIdleCallback||(e=>setTimeout(e,1));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{ue(),fe(),pe(()=>ge())}):(ue(),fe(),pe(()=>ge())),r("Pixel script loaded")})();})();
|
|
102
|
+
`,this.shadow.getElementById("accept")?.addEventListener("click",()=>this.handleConsent(!0)),this.shadow.getElementById("decline")?.addEventListener("click",()=>this.handleConsent(!1))}handleConsent(t){window.balance?.setConsent&&window.balance.setConsent({analytics:t,marketing:t,personalization:t,timestamp:new Date().toISOString()}),t&&!window._balanceInitialPageviewFired&&(window._balanceInitialPageviewFired=!0,window.balance?.page&&window.balance.page(),ee(),i("Initial pageview fired after consent granted")),this.remove()}remove(){this.container&&(this.container.remove(),this.container=null,this.shadow=null,i("ConsentManager: Banner removed"))}}function he(){try{return b==="local"?localStorage:sessionStorage}catch{return null}}function U(e){let t=he();if(!t)return null;try{let n=x+e,o=t.getItem(n);if(!o&&b==="session")try{o=localStorage.getItem(n)}catch{}return o}catch{return null}}function T(e,t){let n=he();if(n)try{n.setItem(x+e,t)}catch{}}function be(){if(b!=="local"){i("Upgrading storage tier: session -> local");try{let e=[];for(let t=0;t<sessionStorage.length;t++){let n=sessionStorage.key(t);n?.startsWith(x)&&e.push(n)}for(let t of e){let n=sessionStorage.getItem(t);n&&localStorage.setItem(t,n)}for(let t of e)sessionStorage.removeItem(t);b="local",i(`Storage tier upgraded, migrated ${e.length} items`)}catch(e){v(" Storage migration failed:",e)}}}function Q(){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 Ve(){try{let e=U(de),t=U(W);if(e&&t&&Date.now()-parseInt(t,10)<Me)return T(W,Date.now().toString()),e;let n=Q();return T(de,n),T(W,Date.now().toString()),n}catch{return Q()}}function Ke(){let e=new URLSearchParams(window.location.search),t={};return["source","medium","campaign","content","term"].forEach(n=>{let o=e.get(`utm_${n}`);o&&(t[`utm_${n}`]=o)}),t}function Ye(){try{let e=U(ue);if(e){_=JSON.parse(e),i("Loaded attribution:",_);return}let t=Ke();Object.keys(t).length>0&&(_=t,T(ue,JSON.stringify(t)),i("Captured attribution:",_))}catch{}}function Je(){try{m=U(fe)}catch{}}function we(){if(!s?.analytics)return null;try{let e=localStorage.getItem(x+q);if(e)return e;let t=Q();return localStorage.setItem(x+q,t),i("Created persistent visitor ID:",t.substring(0,8)+"..."),t}catch{return null}}function Xe(){if(!s?.analytics){d=null;return}try{d=localStorage.getItem(x+q),d&&i("Loaded visitor ID:",d.substring(0,8)+"...")}catch{}}function Ge(){try{let e=localStorage.getItem(A);if(e){let t=JSON.parse(e);if(t.expiresAt&&Date.now()>t.expiresAt){i("Consent expired - clearing stored consent"),localStorage.removeItem(A),s=null;return}if(t.expiresAt){let n=t.expiresAt-Date.now();n>0&&n<Ue&&(i("Consent nearing expiration - will prompt for refresh"),window._balanceConsentNeedsRefresh=!0)}s=t.preferences||null,i("Loaded consent:",s)}}catch{}}function ye(e){let t=s;s=e;try{let o={preferences:e,method:"explicit",version:1,expiresAt:Date.now()+Ne};localStorage.setItem(A,JSON.stringify(o)),i("Consent saved with TTL:",e),window._balanceConsentNeedsRefresh=!1}catch(o){v(" Could not save consent:",o)}e.analytics===!0&&(be(),d||(d=we()));let n=w({event_name:"consent_updated",metadata:{consent_preferences:e,consent_method:"explicit",previous_consent:t||void 0}});y(n);try{window.dispatchEvent(new CustomEvent("balance:consent:updated",{detail:e})),i("DOM event balance:consent:updated dispatched")}catch{}}function Qe(){return s}function Ze(e){return s?.[e]===!0}async function et(e){let t=e.toLowerCase().trim(),o=new TextEncoder().encode(t),f=await crypto.subtle.digest("SHA-256",o);return Array.from(new Uint8Array(f)).map(r=>r.toString(16).padStart(2,"0")).join("")}function w(e){let t=Te(),n={artist_id:F,fan_session_id:N,visitor_id:d||void 0,fan_id_hash:m||void 0,timestamp:new Date().toISOString(),source_url:window.location.href,referrer_url:document.referrer||void 0,user_agent:navigator.userAgent,device_type:t.device_type,browser:t.browser,os:t.os,tracking_source:O,...e,..._};return z&&!e.projectId&&(n.projectId=z),n}function y(e){h.push(e),i("Event queued:",e.event_name,"(queue:",h.length,")"),h.length>=10&&L()}async function L(){if(h.length===0)return;let e=[...h];h=[],i("Flushing",e.length,"events to",k);try{let t=await fetch(k,{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){if(v(" Failed to send events, trying fallback:",t),k!==pe&&!B)try{if((await fetch(pe,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:e}),keepalive:!0})).ok){i("Events sent via fallback (no geo)");return}}catch(n){v(" Fallback also failed:",n)}h.length<50&&h.push(...e)}}function tt(){V&&clearInterval(V),V=window.setInterval(()=>{h.length>0&&L()},5e3)}function Z(){S||(K=Date.now()),S=Date.now(),E=!0,i("Active time tracking started/resumed")}function ve(){S&&E&&(Y+=Date.now()-S),E=!1,i("Active time tracking paused, accumulated:",Y,"ms")}function xe(){let e=Y;return E&&S&&(e+=Date.now()-S),e}function nt(){me=Date.now(),C&&(C=!1,Z(),i("User returned from idle"))}function it(){if(document.visibilityState==="hidden"){i("Skipping heartbeat - tab hidden");return}if(Date.now()-me>$e){C||(C=!0,ve(),i("User idle - pausing heartbeat"));return}let e=xe(),t=Math.round(e/1e3),n=w({event_name:"engagement_heartbeat",metadata:{time_on_page_seconds:t,time_on_page_ms:e,heartbeat_interval_ms:j,is_active:E&&!C}});y(n),J++,i("Heartbeat sent:",t,"seconds active")}function ee(){if(!ae){i('Heartbeat disabled via data-heartbeat="false"');return}I&&clearInterval(I),Z(),I=window.setInterval(()=>{it()},j),i("Heartbeat started with interval:",j,"ms")}function te(){if(!X){if(X=!0,I&&(clearInterval(I),I=null),ae){let e=K?Date.now()-K:0,t=xe(),n=w({event_name:"engagement_summary",metadata:{total_time_ms:e,active_time_ms:t,heartbeat_samples:J,page_path:window.location.pathname}});if(navigator.sendBeacon&&k){let o=JSON.stringify({events:[n]});navigator.sendBeacon(k,o),i("Engagement summary sent via sendBeacon:",Math.round(t/1e3),"seconds active")}else y(n),i("Engagement summary enqueued:",Math.round(t/1e3),"seconds active")}J=0}}function D(e={}){let t=e.url||window.location.href;if(He(t)){i("Page excluded from tracking:",t);return}let n=w({event_name:"pageview",page_title:e.title||document.title,source_url:t});y(n)}function ne(e,t={}){let n=w({event_name:"custom",metadata:{event_type:e,...t}});y(n)}async function ke(e,t={}){try{if(s&&s.analytics===!1){i("Identify skipped - user declined analytics consent");return}m=await et(e),s?.analytics===!0&&be(),T(fe,m);let n=e.split("@"),o=n[0].charAt(0)+"***@"+(n[1]||"");i("Fan identified:",{name:t.name||"(no name)",email:o,hash:m.substring(0,16)+"...",traits:t,storageTier:b});let f=w({event_name:"identify",fan_id_hash:m,metadata:{email_sha256:m,email_display:o,traits:t,consent_preferences:s||void 0,storage_tier:b}});y(f)}catch(n){v(" Failed to identify:",n)}}function _e(e,t="USD",n={}){let o=w({event_name:"purchase",metadata:{revenue:e,currency:t,...n}});y(o)}function Ie(){O=Ae(),i("Tracking source detected:",O),Ge(),s?.analytics===!0?(b="local",i("Storage tier: local (analytics consent granted)")):(b="session",i("Storage tier: session (privacy by default)")),N=Ve(),Je(),Xe(),s||i($?"Consent UI enabled, waiting for explicit user consent (Tier 0 mode)":"No consent - operating in privacy-first mode (session storage only, limited tracking)"),s?.analytics&&!d&&(d=we()),Ye(),tt(),i("Initialized",{artistId:F,projectId:z||"(none - will track to all projects)",rawProjectId:H||"(none)",sessionId:N,visitorId:d?d.substring(0,8)+"...":null,fanIdHash:m,consent:s,storageTier:b,trackingSource:O,useEmulator:B,endpoint:k}),s?.analytics===!0?(window._balanceInitialPageviewFired=!0,D(),ee(),i("Full tracking enabled (user consented)")):$?i("Tracking dormant - waiting for explicit consent via ConsentManager"):(window._balanceInitialPageviewFired=!0,D(),ee(),i("Privacy-first tracking enabled (session-scoped, no persistent IDs)")),["mousemove","keydown","scroll","touchstart"].forEach(r=>{document.addEventListener(r,nt,{passive:!0})});let e=window.location.hostname;function t(r){try{let a=new URL(r).hostname.toLowerCase();return a.includes("spotify")?"spotify":a.includes("apple")||a.includes("music.apple")?"apple_music":a.includes("youtube")||a.includes("youtu.be")?"youtube":a.includes("soundcloud")?"soundcloud":a.includes("tidal")?"tidal":a.includes("deezer")?"deezer":a.includes("amazon")||a.includes("music.amazon")?"amazon_music":a.includes("bandcamp")?"bandcamp":a.includes("lnk.to")||a.includes("linkfire")?"linkfire":a.includes("linktr.ee")?"linktree":a.includes("shop")||a.includes("store")||a.includes("merch")?"shop":a.includes("ticketmaster")||a.includes("eventbrite")||a.includes("dice.fm")?"tickets":a.includes("instagram")?"instagram":a.includes("twitter")||a.includes("x.com")?"twitter":a.includes("tiktok")?"tiktok":a.includes("facebook")?"facebook":"external"}catch{return"external"}}function n(r){try{return new URL(r,window.location.origin).hostname!==e}catch{return!1}}function o(r,a){let c=t(r),R=a?.textContent?.trim().substring(0,100)||"",ot=a?.id||a?.getAttribute("data-link-id")||void 0;i("External link clicked:",{url:r,platform:c,linkText:R}),ne("page_link_click",{link_url:r,link_text:R,link_id:ot,platform:c,link_type:"external"})}let f=window.open;if(window.open=function(r,a,c){if(r){let R=r.toString();n(R)&&o(R)}return f.call(window,r,a,c)},i("window.open interception enabled (always on)"),l?.dataset.autoTrackLinks==="true"&&(document.addEventListener("click",r=>{let c=r.target.closest("a");if(c&&c.href&&n(c.href)){if(le&&(ge(c.href)||c.hasAttribute("download")))return;o(c.href,c)}},{capture:!0,passive:!0}),i("External link click listener enabled (opt-in)")),le&&(document.addEventListener("click",r=>{let c=r.target.closest("a");c?.href&&(ge(c.href)||c.hasAttribute("download"))&&Be(c.href,c)},{capture:!0,passive:!0}),i("File download tracking enabled")),Oe){let r=window.location.href;window.addEventListener("hashchange",()=>{let a=window.location.href;a!==r&&(r=a,setTimeout(()=>{D({title:document.title,url:a})},0))}),i("Hash routing tracking enabled")}document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"?(ve(),te(),L()):(Z(),X=!1)}),window.addEventListener("pagehide",()=>{te(),L()}),window.addEventListener("beforeunload",()=>{te(),L()})}if(window.balance?._version&&window.balance._version!==g){console.warn(`[BLN] Version conflict: ${window.balance._version} already loaded, skipping ${g}`);return}let ie=window.balance?.q||[];function Se(){if(ie.length>0){i("Processing",ie.length,"queued commands");for(let e of ie){let[t,...n]=e;switch(t){case"track":ne(n[0],n[1]);break;case"identify":ke(n[0],n[1]);break;case"page":D(n[0]);break;case"purchase":_e(n[0],n[1],n[2]);break;case"setConsent":ye(n[0]);break;default:i("Unknown queued command:",t)}}}}window.balance={track:ne,identify:ke,page:D,purchase:_e,getSessionId:()=>N,getVisitorId:()=>d,getFanIdHash:()=>m,getAttribution:()=>_,setConsent:ye,getConsent:Qe,hasConsent:Ze,_version:g};function Ee(){$&&!s&&new qe({style:De,primaryColor:Pe,position:Re})}let Ce=window.requestIdleCallback||(e=>setTimeout(e,1));document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{Ie(),Se(),Ce(()=>Ee())}):(Ie(),Se(),Ce(()=>Ee())),i("Pixel script loaded")})();})();
|
package/dist/index.js
CHANGED
|
@@ -1521,6 +1521,10 @@ function BalanceProvider({
|
|
|
1521
1521
|
scriptUrl,
|
|
1522
1522
|
endpoint,
|
|
1523
1523
|
useEmulator = false,
|
|
1524
|
+
exclude,
|
|
1525
|
+
trackFileDownloads = false,
|
|
1526
|
+
hashRouting = false,
|
|
1527
|
+
integrity,
|
|
1524
1528
|
children
|
|
1525
1529
|
}) {
|
|
1526
1530
|
const [isReady, setIsReady] = (0, import_react11.useState)(false);
|
|
@@ -1685,6 +1689,11 @@ function BalanceProvider({
|
|
|
1685
1689
|
"data-endpoint": endpoint,
|
|
1686
1690
|
"data-emulator": useEmulator ? "true" : void 0,
|
|
1687
1691
|
"data-debug": debug ? "true" : void 0,
|
|
1692
|
+
"data-exclude-pages": exclude?.join(",") || void 0,
|
|
1693
|
+
"data-track-file-downloads": trackFileDownloads ? "true" : void 0,
|
|
1694
|
+
"data-hash-routing": hashRouting ? "true" : void 0,
|
|
1695
|
+
integrity,
|
|
1696
|
+
crossOrigin: integrity ? "anonymous" : void 0,
|
|
1688
1697
|
strategy: "afterInteractive",
|
|
1689
1698
|
onLoad: handleScriptLoad,
|
|
1690
1699
|
onError: handleScriptError
|
package/dist/index.mjs
CHANGED
|
@@ -1445,6 +1445,10 @@ function BalanceProvider({
|
|
|
1445
1445
|
scriptUrl,
|
|
1446
1446
|
endpoint,
|
|
1447
1447
|
useEmulator = false,
|
|
1448
|
+
exclude,
|
|
1449
|
+
trackFileDownloads = false,
|
|
1450
|
+
hashRouting = false,
|
|
1451
|
+
integrity,
|
|
1448
1452
|
children
|
|
1449
1453
|
}) {
|
|
1450
1454
|
const [isReady, setIsReady] = useState4(false);
|
|
@@ -1609,6 +1613,11 @@ function BalanceProvider({
|
|
|
1609
1613
|
"data-endpoint": endpoint,
|
|
1610
1614
|
"data-emulator": useEmulator ? "true" : void 0,
|
|
1611
1615
|
"data-debug": debug ? "true" : void 0,
|
|
1616
|
+
"data-exclude-pages": exclude?.join(",") || void 0,
|
|
1617
|
+
"data-track-file-downloads": trackFileDownloads ? "true" : void 0,
|
|
1618
|
+
"data-hash-routing": hashRouting ? "true" : void 0,
|
|
1619
|
+
integrity,
|
|
1620
|
+
crossOrigin: integrity ? "anonymous" : void 0,
|
|
1612
1621
|
strategy: "afterInteractive",
|
|
1613
1622
|
onLoad: handleScriptLoad,
|
|
1614
1623
|
onError: handleScriptError
|