@@ -3,20 +3,27 @@ import { Request} from 'firebase-functions/lib/providers/https'
33import * as express from "express" ;
44const 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
811export 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} )
0 commit comments