Skip to content

Commit

Permalink
chore: use nullish coalesce
Browse files Browse the repository at this point in the history
  • Loading branch information
jbergstroem committed Jan 23, 2025
1 parent e9a43da commit 1211aaf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ Finally, in case you are using banners and want to have further control on the a
</div>
```

### Overriding default opaqueUserId behavior
### Overriding default User ID behavior

If you want to pass your own `opaqueUserId` to the library, you can do so by overiding the `getUserID()` function which is
responsible for retrieving a unique identifier for the user. It should additionally set a new value if none is found. This function should return a string with the `opaqueUserId` passed in the events.
If you want to pass your own User ID when sending events, you can do so by overiding the `getUserID()` function which is
responsible for retrieving a unique identifier for the user. It should additionally set a new value if none is found. This function should return a string with the User ID (as a string) passed in the events.

```javascript
window.TS = {
Expand Down
4 changes: 2 additions & 2 deletions src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function getEvent(type: EventType, node: HTMLElement): ProductEvent {
let product = node.dataset.tsProduct;
let bid = node.dataset.tsResolvedBid;
let additionalProduct: string | undefined = undefined;
if (bid == "inherit" && product && (type == "Click" || type == "Impression")) {
if (bid === "inherit" && product && (type === "Click" || type === "Impression")) {
bid = bidStore.get();
additionalProduct = product;
product = undefined;
Expand All @@ -227,7 +227,7 @@ function getEvent(type: EventType, node: HTMLElement): ProductEvent {
t: Date.now(),
page: getPage(),
id: generateId(),
uid: window.TS.getUserId() || getUserId(),
uid: window.TS.getUserId() ?? getUserId(),

Check failure on line 230 in src/detector.ts

View workflow job for this annotation

GitHub Actions / lint

Cannot invoke an object which is possibly 'undefined'.
};
if (type === "Purchase") {
event.items = JSON.parse(node.dataset.tsItems || "[]");
Expand Down

0 comments on commit 1211aaf

Please sign in to comment.