Skip to content

Commit fe75363

Browse files
committed
cleanup the tracker code
1 parent e2620e6 commit fe75363

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

packages/tracker/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "0.0.1",
44
"description": "Databuddy Analytics Tracker Scripts",
55
"type": "module",
6-
"module": "dist/databuddy.js",
76
"scripts": {
87
"build": "bun build.ts",
98
"deploy": "bun deploy.ts",

packages/tracker/src/core/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function getTrackerConfig(): TrackerOptions {
4646
let script = document.currentScript as HTMLScriptElement;
4747

4848
if (!script) {
49-
// Fallback for module scripts where document.currentScript is null
49+
// Fallback for scripts where document.currentScript is null
5050
const scripts = document.getElementsByTagName('script');
5151
for (let i = 0; i < scripts.length; i++) {
5252
const src = scripts[i].src;

packages/tracker/tests/general.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ test.describe("General Tracking", () => {
2525
expect(tracker.clientId).toBe("test-client-id");
2626
});
2727

28-
test("initializes via data- attributes (classic script)", async ({ page }) => {
28+
test("initializes via data- attributes", async ({ page }) => {
2929
await page.goto("/");
30-
// We inject a script tag manually to simulate classic script usage with data attributes
3130
await page.evaluate(() => {
3231
const script = document.createElement('script');
3332
script.src = "/dist/databuddy.js";
34-
script.type = "module";
3533
script.setAttribute("data-client-id", "data-attr-client");
3634
script.setAttribute("data-ignore-bot-detection", "true");
3735
document.body.appendChild(script);
@@ -44,14 +42,11 @@ test.describe("General Tracking", () => {
4442
expect(tracker.ignoreBotDetection).toBe(true);
4543
});
4644

47-
test("initializes via query parameters (classic script)", async ({ page }) => {
45+
test("initializes via query parameters", async ({ page }) => {
4846
await page.goto("/");
49-
// We inject a script tag manually to simulate classic script usage with query params
5047
await page.evaluate(() => {
5148
const script = document.createElement('script');
5249
script.src = "/dist/databuddy.js?clientId=query-param-client&ignoreBotDetection=true";
53-
// Since build outputs ESM, we need to treat it as a module
54-
script.type = "module";
5550
document.body.appendChild(script);
5651
});
5752

@@ -76,7 +71,6 @@ test.describe("General Tracking", () => {
7671
await page.evaluate(() => {
7772
(window as any).databuddyConfig = { clientId: "test-client-id", ignoreBotDetection: true };
7873
});
79-
// Ensure module type
8074
await page.addScriptTag({ url: "/dist/databuddy.js" });
8175

8276
const request = await requestPromise;
@@ -92,7 +86,6 @@ test.describe("General Tracking", () => {
9286
await page.evaluate(() => {
9387
(window as any).databuddyConfig = { clientId: "test-client-id", ignoreBotDetection: true };
9488
});
95-
// Ensure module type
9689
await page.addScriptTag({ url: "/dist/databuddy.js" });
9790

9891
await expect.poll(async () => await page.evaluate(() => !!(window as any).db)).toBeTruthy();
@@ -131,7 +124,6 @@ test.describe("General Tracking", () => {
131124
await page.evaluate(() => {
132125
(window as any).databuddyConfig = { clientId: "test-client-id" }; // ignoreBotDetection defaults to false
133126
});
134-
// Ensure module type
135127
await page.addScriptTag({ url: "/dist/databuddy.js" });
136128

137129
// Wait a bit to ensure no request is fired

0 commit comments

Comments
 (0)