Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename installation events #31

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/installation-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function installationHandler({ previousVersion, reason }) {
const { version } = chrome.runtime.getManifest()

if (reason === 'install') {
await sendTrackEvent({ name: 'installed', params: { version } })
await sendTrackEvent({ name: 'custom-installed', params: { version } })
.then(saveLastInstalledVersion)
.then(() => console.debug(`lastInstalledVersion is set: ${version}`))
} else if (reason === 'update') {
Expand All @@ -24,11 +24,11 @@ export async function installationHandler({ previousVersion, reason }) {
// if already installed, just update the version
if (lastInstalledVersion) {
console.debug(`lastInstalledVersion is ${lastInstalledVersion}`)
sendTrackEvent({ name: 'updated', params: { version, previousVersion } })
sendTrackEvent({ name: 'custom-updated', params: { version, previousVersion } })
return
}

sendTrackEvent({ name: 'installed', params: { version } })
sendTrackEvent({ name: 'custom-installed', params: { version } })
.then(saveLastInstalledVersion)
})
}
Expand Down
6 changes: 3 additions & 3 deletions test/installation-hander.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('installationHandler', () => {
it('should send installed event to google analytics', async () => {
await installationHandler({ reason: 'install' })

expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'installed', params: { version: '4.4.4' } })
expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'custom-installed', params: { version: '4.4.4' } })
expect(chrome.storage.local.set).toHaveBeenCalledWith({ lastInstalledVersion: '4.4.4' })
})
})
Expand All @@ -37,15 +37,15 @@ describe('installationHandler', () => {
chrome.storage.local.get.mockReturnValue(Promise.resolve({ lastInstalledVersion: '3.3.3' }))
await installationHandler({ reason: 'update', previousVersion: '4.4.3' })

expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'updated', params: { version: '4.4.4', previousVersion: '4.4.3' } })
expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'custom-updated', params: { version: '4.4.4', previousVersion: '4.4.3' } })
expect(chrome.storage.local.set).not.toHaveBeenCalled()
})

it('should send installed event if latestInstalledVersion is not set', async () => {
chrome.storage.local.get.mockReturnValue(Promise.resolve({ lastInstalledVersion: null }))
await installationHandler({ reason: 'update', previousVersion: '4.4.3' })

expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'installed', params: { version: '4.4.4' } })
expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'custom-installed', params: { version: '4.4.4' } })
})
})
})
Loading