Skip to content

Commit

Permalink
Emit Reset Events (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooyaj authored Nov 30, 2022
1 parent 03e6383 commit 6e42f6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-lamps-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@segment/analytics-next': minor
---

Emit a `reset` event when analytics.reset() is called
10 changes: 10 additions & 0 deletions packages/browser/src/core/analytics/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,15 @@ describe('Analytics', () => {
storedData = getAjsBrowserStorage()
expect(storedData).toEqual({})
})

it('emits a reset event', async () => {
const analytics = new Analytics({ writeKey: '' })
const fn = jest.fn()
analytics.on('reset', fn)
analytics.user().id('known-user')

analytics.reset()
expect(fn).toHaveBeenCalledTimes(1)
})
})
})
1 change: 1 addition & 0 deletions packages/browser/src/core/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export class Analytics
reset(): void {
this._user.reset()
this._group.reset()
this.emit('reset')
}

timeout(timeout: number): void {
Expand Down

0 comments on commit 6e42f6e

Please sign in to comment.