Skip to content

Commit

Permalink
fix: add automatic deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Oct 31, 2024
1 parent 0c013ba commit bc72637
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/large-waves-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'analytics-plugin-trench': patch
'trench-js': patch
---

Adds automatic deduplication of events
7 changes: 7 additions & 0 deletions packages/analytics-plugin-trench/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export function trench(config: TrenchConfig) {
return;
}

const lastEvents = getGlobalValue<BaseEvent[]>('lastEvents');

if (lastEvents && JSON.stringify(events) === JSON.stringify(lastEvents)) {
return;
}
setGlobalValue('lastEvents', events);

await fetch(`${removeTrailingSlash(config.serverUrl)}/events`, {
method: 'POST',
headers: {
Expand Down

0 comments on commit bc72637

Please sign in to comment.