basic sprig integration with possible page URL events (#932)
* basic sprig integration with possible page URL events * iteration 0 * iteration 1 * run prettier; attempt to remove expect error * readd expect error messages * typescript comment fixes * add identify * remove package-lock.json * extract to separate file * fix linting * fix lint * fix lint * fix missing config
This commit is contained in:
parent
a12ed78813
commit
7ba19c274b
|
@ -18,4 +18,5 @@ export const DEV_CONFIG: EnvConfig = {
|
||||||
amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3',
|
amplitudeApiKey: 'fd8cbfd964b9a205b8678a39faae71b3',
|
||||||
// this is Phil's deployment
|
// this is Phil's deployment
|
||||||
twitchBotEndpoint: 'https://king-prawn-app-5btyw.ondigitalocean.app',
|
twitchBotEndpoint: 'https://king-prawn-app-5btyw.ondigitalocean.app',
|
||||||
|
sprigEnvironmentId: 'Tu7kRZPm7daP',
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ export type EnvConfig = {
|
||||||
firebaseConfig: FirebaseConfig
|
firebaseConfig: FirebaseConfig
|
||||||
amplitudeApiKey?: string
|
amplitudeApiKey?: string
|
||||||
twitchBotEndpoint?: string
|
twitchBotEndpoint?: string
|
||||||
|
sprigEnvironmentId?: string
|
||||||
|
|
||||||
// IDs for v2 cloud functions -- find these by deploying a cloud function and
|
// IDs for v2 cloud functions -- find these by deploying a cloud function and
|
||||||
// examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app
|
// examining the URL, https://[name]-[cloudRunId]-[cloudRunRegion].a.run.app
|
||||||
|
@ -56,6 +57,7 @@ type FirebaseConfig = {
|
||||||
export const PROD_CONFIG: EnvConfig = {
|
export const PROD_CONFIG: EnvConfig = {
|
||||||
domain: 'manifold.markets',
|
domain: 'manifold.markets',
|
||||||
amplitudeApiKey: '2d6509fd4185ebb8be29709842752a15',
|
amplitudeApiKey: '2d6509fd4185ebb8be29709842752a15',
|
||||||
|
sprigEnvironmentId: 'sQcrq9TDqkib',
|
||||||
|
|
||||||
firebaseConfig: {
|
firebaseConfig: {
|
||||||
apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw',
|
apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw',
|
||||||
|
|
|
@ -6,6 +6,8 @@ import {
|
||||||
Identify,
|
Identify,
|
||||||
} from '@amplitude/analytics-browser'
|
} from '@amplitude/analytics-browser'
|
||||||
|
|
||||||
|
import * as Sprig from 'web/lib/service/sprig'
|
||||||
|
|
||||||
import { ENV_CONFIG } from 'common/envs/constants'
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
|
|
||||||
init(ENV_CONFIG.amplitudeApiKey ?? '', undefined, { includeReferrer: true })
|
init(ENV_CONFIG.amplitudeApiKey ?? '', undefined, { includeReferrer: true })
|
||||||
|
@ -33,10 +35,12 @@ export const withTracking =
|
||||||
|
|
||||||
export async function identifyUser(userId: string) {
|
export async function identifyUser(userId: string) {
|
||||||
setUserId(userId)
|
setUserId(userId)
|
||||||
|
Sprig.setUserId(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setUserProperty(property: string, value: string) {
|
export async function setUserProperty(property: string, value: string) {
|
||||||
const identifyObj = new Identify()
|
const identifyObj = new Identify()
|
||||||
identifyObj.set(property, value)
|
identifyObj.set(property, value)
|
||||||
await identify(identifyObj)
|
await identify(identifyObj)
|
||||||
|
Sprig.setAttributes({ [property]: value })
|
||||||
}
|
}
|
||||||
|
|
33
web/lib/service/sprig.ts
Normal file
33
web/lib/service/sprig.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-nocheck
|
||||||
|
// Integrate Sprig
|
||||||
|
|
||||||
|
import { ENV_CONFIG } from 'common/envs/constants'
|
||||||
|
|
||||||
|
try {
|
||||||
|
;(function (l, e, a, p) {
|
||||||
|
if (window.Sprig) return
|
||||||
|
window.Sprig = function (...args) {
|
||||||
|
S._queue.push(args)
|
||||||
|
}
|
||||||
|
const S = window.Sprig
|
||||||
|
S.appId = a
|
||||||
|
S._queue = []
|
||||||
|
window.UserLeap = S
|
||||||
|
a = l.createElement('script')
|
||||||
|
a.async = 1
|
||||||
|
a.src = e + '?id=' + S.appId
|
||||||
|
p = l.getElementsByTagName('script')[0]
|
||||||
|
p.parentNode.insertBefore(a, p)
|
||||||
|
})(document, 'https://cdn.sprig.com/shim.js', ENV_CONFIG.sprigEnvironmentId)
|
||||||
|
} catch (error) {
|
||||||
|
console.log('Error initializing Sprig, please complain to Barak', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setUserId(userId: string): void {
|
||||||
|
window.Sprig.setUserId(userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setAttributes(attributes: Record<string, unknown>): void {
|
||||||
|
window.Sprig.setAttributes(attributes)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user