From 0849b3fc3e8314b90d2afb788631c52e0754c27c Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Mon, 22 Apr 2024 15:55:06 +0200 Subject: [PATCH] feat(screeb): identify on init (#1990) * feat(screeb): identify on init * fix(screeb): use js typing instead of segment for visitorId --- .../destinations/screeb/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/browser-destinations/destinations/screeb/src/index.ts b/packages/browser-destinations/destinations/screeb/src/index.ts index d65e4347ac..72dac0e262 100644 --- a/packages/browser-destinations/destinations/screeb/src/index.ts +++ b/packages/browser-destinations/destinations/screeb/src/index.ts @@ -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' @@ -59,7 +60,7 @@ export const destination: BrowserDestinationDefinition = { } ], - initialize: async ({ settings }, deps) => { + initialize: async ({ settings, analytics }, deps) => { const preloadFunction = function (...args: unknown[]) { if (window.$screeb.q) { window.$screeb.q.push(args) @@ -71,7 +72,12 @@ export const destination: BrowserDestinationDefinition = { 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 },