Skip to content

Commit 2daa5f6

Browse files
committed
Use document.currentScript instead
1 parent 2276344 commit 2daa5f6

File tree

1 file changed

+1
-17
lines changed

1 file changed

+1
-17
lines changed

packages/script/src/index.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@
1717
expires: new Date(Date.now() + COOKIE_EXPIRES),
1818
};
1919

20-
function getScript() {
21-
const scripts = document.querySelectorAll('script');
22-
23-
for (let i = 0; i < scripts.length; i++) {
24-
if (
25-
scripts[i].src &&
26-
(scripts[i].src.includes('dubcdn.com/analytics/script.js') || // production script
27-
scripts[i].src.includes('.dub-cdn.pages.dev/analytics/script.js')) // staging script
28-
) {
29-
return scripts[i];
30-
}
31-
}
32-
33-
return null;
34-
}
35-
3620
function getOptions(script) {
3721
if (!script) {
3822
return null;
@@ -55,7 +39,7 @@
5539
};
5640
}
5741

58-
const script = getScript();
42+
const script = document.currentScript;
5943
if (!script) {
6044
console.error('[Dub Analytics] Script not found.');
6145
return;

0 commit comments

Comments
 (0)