Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -86,7 +86,7 @@
JSON.stringify(outputObject)
);
} catch (error) {
console.error('Error updating anonymous session:', error);

Check warning on line 89 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}
}

Expand All @@ -98,7 +98,7 @@
validation: {}
})
.then((response) => {
const criteriaData: any = response.data;

Check warning on line 101 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
if (criteriaData) {
localStorage.setItem(
SHARED_PREFS_CRITERIA,
Expand All @@ -107,7 +107,7 @@
}
})
.catch((e) => {
console.log('response', e);

Check warning on line 110 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
});
}

Expand Down Expand Up @@ -162,7 +162,7 @@
return checker.getMatchedCriteria(criteriaData);
}
} catch (error) {
console.error('checkCriteriaCompletion', error);

Check warning on line 165 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
}

return null;
Expand All @@ -175,7 +175,7 @@

const dataFields = {
...events.find(
(event: any) => event[SHARED_PREFS_EVENT_TYPE] === UPDATE_USER

Check warning on line 178 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
)
};
delete dataFields[SHARED_PREFS_EVENT_TYPE];
Expand Down Expand Up @@ -222,10 +222,17 @@
SHARED_PREFS_EVENT_LIST_KEY,
JSON.stringify(
events.filter(
(event: any) => event[SHARED_PREFS_EVENT_TYPE] !== UPDATE_USER

Check warning on line 225 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
)
)
);

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

if (onAnonUserCreated) {
onAnonUserCreated(userId);
}
if (anonUserIdSetter !== null) {
await anonUserIdSetter(userId);
}
Expand Down Expand Up @@ -296,7 +303,7 @@
if (shouldOverWrite) {
const trackingType = newDataObject[SHARED_PREFS_EVENT_TYPE];
const indexToUpdate = previousDataArray.findIndex(
(obj: any) => obj[SHARED_PREFS_EVENT_TYPE] === trackingType

Check warning on line 306 in src/anonymousUserTracking/anonymousUserEventManager.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
);
if (indexToUpdate !== -1) {
const dataToUpdate = previousDataArray[indexToUpdate];
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
Loading