Skip to content

Commit fdce15e

Browse files
refactor(audience): move SESSION_START/SESSION_END constants to core
Both the SDK and pixel use these event names — they belong in @imtbl/audience-core so both surfaces import from one place. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fcf6063 commit fdce15e

5 files changed

Lines changed: 10 additions & 11 deletions

File tree

packages/audience/core/src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ export const SESSION_COOKIE = '_imtbl_sid';
1717
export const COOKIE_MAX_AGE_SECONDS = 365 * 24 * 60 * 60 * 2; // 2 years
1818
export const SESSION_MAX_AGE = 30 * 60; // 30 minutes in seconds
1919

20+
export const SESSION_START = 'session_start';
21+
export const SESSION_END = 'session_end';
22+
2023
export const getBaseUrl = (environment: Environment): string => BASE_URLS[environment];

packages/audience/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export {
3434
COOKIE_NAME,
3535
SESSION_COOKIE,
3636
SESSION_MAX_AGE,
37+
SESSION_START,
38+
SESSION_END,
3739
} from './config';
3840

3941
export { generateId, getTimestamp, isBrowser } from './utils';

packages/audience/sdk/src/config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,3 @@ export const LOG_PREFIX = '[audience]';
1010

1111
/** Default consent source when consentSource is not provided in config. */
1212
export const DEFAULT_CONSENT_SOURCE = 'WebSDK';
13-
14-
// --- Auto-tracked event names ---
15-
// These are fired by the SDK lifecycle, not by studio code.
16-
17-
/** Fired on init (or consent upgrade from none) when no active session cookie exists. */
18-
export const SESSION_START = 'session_start';
19-
/** Fired on explicit shutdown(). Not fired on tab close or consent revocation. */
20-
export const SESSION_END = 'session_end';

packages/audience/sdk/src/sdk.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
COOKIE_NAME, SESSION_COOKIE, INGEST_PATH, CONSENT_PATH,
2+
COOKIE_NAME, SESSION_COOKIE, INGEST_PATH, CONSENT_PATH, SESSION_START, SESSION_END,
33
} from '@imtbl/audience-core';
44
import { Audience } from './sdk';
5-
import { LIBRARY_NAME, SESSION_START, SESSION_END } from './config';
5+
import { LIBRARY_NAME } from './config';
66

77
// --- Test fixtures ---
88
const TEST_USER = { uid: 'user@example.com', provider: 'email' } as const;

packages/audience/sdk/src/sdk.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import {
2626
collectAttribution,
2727
getOrCreateSession,
2828
createConsentManager,
29+
SESSION_START,
30+
SESSION_END,
2931
} from '@imtbl/audience-core';
3032
import { DebugLogger } from './debug';
3133
import type { AudienceConfig } from './types';
3234
import {
33-
LIBRARY_NAME, LIBRARY_VERSION, LOG_PREFIX, DEFAULT_CONSENT_SOURCE, SESSION_START, SESSION_END,
35+
LIBRARY_NAME, LIBRARY_VERSION, LOG_PREFIX, DEFAULT_CONSENT_SOURCE,
3436
} from './config';
3537

3638
/**

0 commit comments

Comments
 (0)