Skip to content

Commit

Permalink
feat(screeb): identify on init (#1990)
Browse files Browse the repository at this point in the history
* feat(screeb): identify on init

* fix(screeb): use js typing instead of segment for visitorId
  • Loading branch information
samber authored Apr 22, 2024
1 parent 6fc6fde commit 0849b3f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/browser-destinations/destinations/screeb/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Settings } from './generated-types'
import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types'
import { browserDestination } from '@segment/browser-destination-runtime/shim'
import { ID } from '@segment/analytics-next'
import { Screeb } from './types'
import { defaultValues } from '@segment/actions-core'
import identify from './identify'
Expand Down Expand Up @@ -59,7 +60,7 @@ export const destination: BrowserDestinationDefinition<Settings, Screeb> = {
}
],

initialize: async ({ settings }, deps) => {
initialize: async ({ settings, analytics }, deps) => {
const preloadFunction = function (...args: unknown[]) {
if (window.$screeb.q) {
window.$screeb.q.push(args)
Expand All @@ -71,7 +72,12 @@ export const destination: BrowserDestinationDefinition<Settings, Screeb> = {
await deps.loadScript('https://t.screeb.app/tag.js')
await deps.resolveWhen(() => window.$screeb !== preloadFunction, 500)

window.$screeb('init', settings.websiteId)
let visitorId: string | null | undefined = null
if (analytics.user().id()) {
visitorId = analytics.user().id()
}

window.$screeb('init', settings.websiteId, { identity: { id: visitorId } })

return window.$screeb
},
Expand Down

0 comments on commit 0849b3f

Please sign in to comment.