extract to separate file
This commit is contained in:
parent
210b52ac5d
commit
2e8f10ab64
|
@ -6,43 +6,14 @@ 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 })
|
||||||
|
|
||||||
export { track }
|
export { track }
|
||||||
|
|
||||||
// Integrate Sprig
|
|
||||||
|
|
||||||
try {
|
|
||||||
;(function (l, e, a, p) {
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
if (window.Sprig) return
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
window.Sprig = function (...args) {
|
|
||||||
S._queue.push(args)
|
|
||||||
}
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
const S = window.Sprig
|
|
||||||
S.appId = a
|
|
||||||
S._queue = []
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
window.UserLeap = S
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
a = l.createElement('script')
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
a.async = 1
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
a.src = e + '?id=' + S.appId
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
p = l.getElementsByTagName('script')[0]
|
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convenience functions:
|
// Convenience functions:
|
||||||
|
|
||||||
export const trackCallback =
|
export const trackCallback =
|
||||||
|
@ -64,14 +35,12 @@ export const withTracking =
|
||||||
|
|
||||||
export async function identifyUser(userId: string) {
|
export async function identifyUser(userId: string) {
|
||||||
setUserId(userId)
|
setUserId(userId)
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
Sprig.setUserId(userId)
|
||||||
window.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)
|
||||||
// @ts-expect-error Sprig doesn't yet have a native typescript snippet
|
Sprig.setAttributes(identifyObj)
|
||||||
window.Sprig.setAttribute(property, value)
|
|
||||||
}
|
}
|
||||||
|
|
30
web/lib/service/sprig.ts
Normal file
30
web/lib/service/sprig.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
// @ts-nocheck
|
||||||
|
// Integrate Sprig
|
||||||
|
|
||||||
|
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: Object): void {
|
||||||
|
window.Sprig.setAttributes(attributes)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user