Skip to content

Commit

Permalink
[MOB-9639] Added handler for notifying customer app of a newly create…
Browse files Browse the repository at this point in the history
…d anon userid (#460)

* [MOB-9578] implements identity resolution

* [MOB-9639] Added handler for notifying customer app of a newly created anon userid

* moved onAnonUserCreated in identityResolution
  • Loading branch information
darshan-iterable authored Oct 7, 2024
1 parent c720d4f commit 275b460
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
7 changes: 6 additions & 1 deletion react-example/src/indexWithoutJWT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ const HomeLink = styled(Link)`
configOptions: {
isEuIterableService: false,
dangerouslyAllowJsPopups: true,
enableAnonTracking: true
enableAnonTracking: true,
identityResolution: {
onAnonUserCreated: (userId: string) => {
console.log('onAnonUserCreated', userId);
}
}
}
};

Expand Down
7 changes: 7 additions & 0 deletions src/anonymousUserTracking/anonymousUserEventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ export class AnonymousUserEventManager {
)
)
);

const onAnonUserCreated =
config.getConfig('identityResolution')?.onAnonUserCreated;

if (onAnonUserCreated) {
onAnonUserCreated(userId);
}
if (anonUserIdSetter !== null) {
await anonUserIdSetter(userId);
}
Expand Down
11 changes: 7 additions & 4 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { BASE_URL, DEFAULT_EVENT_THRESHOLD_LIMIT } from '../constants';

type IdentityResolution = {
replayOnVisitorToKnown?: boolean;
mergeOnAnonymousToKnown?: boolean;
onAnonUserCreated?: (userId: string) => void;
};

export type Options = {
logLevel: 'none' | 'verbose';
baseURL: string;
enableAnonTracking: boolean;
isEuIterableService: boolean;
dangerouslyAllowJsPopups: boolean;
eventThresholdLimit?: number;
identityResolution?: {
replayOnVisitorToKnown?: boolean;
mergeOnAnonymousToKnown?: boolean;
};
identityResolution?: IdentityResolution;
};

const _config = () => {
Expand Down

0 comments on commit 275b460

Please sign in to comment.