Skip to content

Commit

Permalink
Rename installation events
Browse files Browse the repository at this point in the history
  • Loading branch information
satoryu committed Sep 25, 2024
1 parent 3328e7f commit e117d86
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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' } })
})
})
})

0 comments on commit e117d86

Please sign in to comment.