Skip to content

Commit 343bfb4

Browse files
authored
Merge pull request #9 from WorldBrain/feature/uninstall-event
Uninstall event - Split out redirect and logging
2 parents e18efa9 + b4419b0 commit 343bfb4

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

firebase/functions/src/analytics/index.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@ import { Request} from 'firebase-functions/lib/providers/https'
33
import * as express from "express";
44
const fetch = require('node-fetch');
55

6-
const appKey = functions.config().countly['app_key']
6+
const config = functions.config();
7+
const appKey = config.countly['app_key']
8+
9+
const redirectUrl = "https://airtable.com/shrZ987GUsOWWMH7L"
710

811
export const uninstall = functions.https.onRequest(async (req: Request, resp: express.Response) => {
12+
let backgroundFunctionUrl = `https://${req.hostname}/uninstallLog?user=${ req.query.user}`
13+
// console.log(`Calling uninstall event: ${backgroundFunctionUrl}`)
14+
fetch(backgroundFunctionUrl)
15+
resp.redirect(redirectUrl)
16+
})
17+
18+
export const uninstallLog = functions.https.onRequest(async (req: Request, resp: express.Response) => {
919

1020
const user = req.query.user
1121
const events = JSON.stringify({
1222
"key": "Global::uninstallExtension",
1323
"count": 1
1424
})
15-
const urlbase = 'https://analytics.worldbrain.io/i'
16-
const urlParams = `${urlbase}?app_key=${appKey}&device_id=${user}&events=${events}`;
17-
const url = `${urlbase}?${urlParams}`
18-
19-
console.log(`Logging uninstall event: ${url}`)
20-
await fetch(url)
21-
resp.redirect(`https://airtable.com/shrZ987GUsOWWMH7L`)
25+
const analyticsUrl = `https://analytics.worldbrain.io/i?app_key=${appKey}&device_id=${user}&events=${events}`;
26+
await fetch(analyticsUrl)
27+
console.log(`Logged uninstall event: ${analyticsUrl}`)
28+
resp.send('Done')
2229
})

firebase/functions/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export { getLoginToken } from './auth'
77
export { getCheckoutLink, getManageLink, userSubscriptionChanged, refreshUserClaims } from './subscriptions'
88
export { generateTwilioNTSToken } from './twilio'
99
export { sendWelcomeEmailOnSignUp } from "./user"
10-
export { uninstall } from "./analytics"
10+
export { uninstall, uninstallLog } from "./analytics"
11+

0 commit comments

Comments
 (0)