-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support passing custom getUserId function
This is useful when you want to handle your own logic for what you want to pass as `opaqueUserId`.
1 parent
efa5b9e
commit 0ee2a5c
Showing
3 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect, test } from "vitest"; | ||
|
||
test("support custom getUserId function", async () => { | ||
window.TS = { | ||
token: "token", | ||
getUserId: () => { | ||
console.log("foo"); | ||
return "custom-user-id"; | ||
}, | ||
}; | ||
const events: any[] = []; | ||
window.addEventListener("topsort", (e) => { | ||
events.push((e as any).detail); | ||
}); | ||
document.body.innerHTML = ` | ||
<div id="product" data-ts-product="product-id-click-1" data-ts-resolved-bid="1247eaae-63a1-4c20-9b52-9efdcdef3095"></div> | ||
`; | ||
await import("./detector"); | ||
|
||
document.getElementById("product")?.click(); | ||
expect(events).toMatchObject([ | ||
{ | ||
type: "Impression", | ||
page: "/", | ||
product: "product-id-click-1", | ||
bid: "1247eaae-63a1-4c20-9b52-9efdcdef3095", | ||
id: expect.stringMatching(/[\d.a-zA-Z-]+/), | ||
uid: "custom-user-id", | ||
}, | ||
{ | ||
type: "Click", | ||
page: "/", | ||
product: "product-id-click-1", | ||
bid: "1247eaae-63a1-4c20-9b52-9efdcdef3095", | ||
id: expect.stringMatching(/[\d.a-zA-Z-]+/), | ||
uid: "custom-user-id", | ||
}, | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters