-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from satoryu/grasp-installations-and-uninstall…
…ations Sends install and update events to GA4
- Loading branch information
Showing
5 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
layout: page | ||
title: Thank You for Using Copy for Scrapbox! | ||
--- | ||
|
||
# Thank you for Using Copy for Scrapbox! | ||
|
||
We are sorry to see you go! Your feedback is important to us. | ||
Please take a moment to let us know why you decided to uninstall the extension. | ||
|
||
- [GitHub Issues](https://github.com/satoryu/copy-for-scrapbox/issues) | ||
- Email: satoryu.1981@gmail.com | ||
|
||
Thank you for your time and feedback! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { sendTrackEvent } from "./google-analytics" | ||
|
||
async function saveLastInstalledVersion() { | ||
const { version } = chrome.runtime.getManifest() | ||
|
||
return chrome.storage.local.set({ lastInstalledVersion: version }) | ||
} | ||
|
||
async function getLastInstalledVersion() { | ||
return chrome.storage.local.get('lastInstalledVersion') | ||
.then(({ lastInstalledVersion }) => lastInstalledVersion) | ||
} | ||
|
||
export async function installationHandler({ previousVersion, reason }) { | ||
const { version } = chrome.runtime.getManifest() | ||
|
||
if (reason === 'install') { | ||
await sendTrackEvent({ name: 'installed', params: { version } }) | ||
.then(saveLastInstalledVersion) | ||
.then(() => console.debug(`lastInstalledVersion is set: ${version}`)) | ||
} else if (reason === 'update') { | ||
await getLastInstalledVersion() | ||
.then((lastInstalledVersion) => { | ||
// if already installed, just update the version | ||
if (lastInstalledVersion) { | ||
console.debug(`lastInstalledVersion is ${lastInstalledVersion}`) | ||
sendTrackEvent({ name: 'updated', params: { version, previousVersion } }) | ||
return | ||
} | ||
|
||
sendTrackEvent({ name: 'installed', params: { version } }) | ||
.then(saveLastInstalledVersion) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { installationHandler } from "../src/installation-handler.js" | ||
import { sendTrackEvent } from "../src/google-analytics.js" | ||
|
||
global.chrome = { | ||
runtime: { | ||
getManifest: () => ({ version: '4.4.4' }) | ||
}, | ||
storage: { | ||
local: { | ||
set: jest.fn(() => Promise.resolve()), | ||
get: jest.fn(() => Promise.resolve({})), | ||
}, | ||
} | ||
} | ||
|
||
jest.mock('../src/google-analytics.js', () => ({ sendTrackEvent: jest.fn() })) | ||
|
||
describe('installationHandler', () => { | ||
beforeEach(() => { | ||
chrome.storage.local.set.mockClear() | ||
sendTrackEvent.mockClear() | ||
|
||
sendTrackEvent.mockReturnValue(Promise.resolve()) | ||
}) | ||
|
||
describe('When the reason is install', () => { | ||
it('should send installed event to google analytics', async () => { | ||
await installationHandler({ reason: 'install' }) | ||
|
||
expect(sendTrackEvent).toHaveBeenCalledWith({ name: 'installed', params: { version: '4.4.4' } }) | ||
expect(chrome.storage.local.set).toHaveBeenCalledWith({ lastInstalledVersion: '4.4.4' }) | ||
}) | ||
}) | ||
|
||
describe('When the reason is update', () => { | ||
it('should send updated event to google analytics', async () => { | ||
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(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' } }) | ||
}) | ||
}) | ||
}) |