Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Add new getGTMUserFieldsData to identity x config
Browse files Browse the repository at this point in the history
This will utilize the gtmUserFields object in the config to return a reader friendly key vaule object to push to the gtm layer.
  • Loading branch information
B77Mills committed Sep 27, 2023
1 parent 2b67301 commit 3a2c9bf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/marko-web-identity-x/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IdentityXConfiguration {
hiddenFields = ['city', 'street', 'addressExtra', 'phoneNumber'],
defaultCountryCode,
booleanQuestionsLabel,
gtmUserFields = {}, // { primary_role: 'ObjectId' }
onHookError,
...rest
} = {}) {
Expand All @@ -45,6 +46,7 @@ class IdentityXConfiguration {
hiddenFields,
defaultCountryCode,
booleanQuestionsLabel,
gtmUserFields,
onHookError: (e) => {
if (process.env.NODE_ENV === 'development') {
log('ERROR IN IDENTITY-X HOOK', e);
Expand Down Expand Up @@ -108,6 +110,19 @@ class IdentityXConfiguration {
return this.getAsArray('requiredServerFields');
}

getGTMUserFieldsData(user) {
if (!user) return {};
const questions = this.getAsObject('gtmUserFields');
const userData = { user_id: user.id };
Object.entries(questions).forEach(([key, value]) => {
const select = user.customSelectFieldAnswers.find(({id: qId}) => qId === value)
if (select && select.answers.length) userData[key] = select.answers.map(({ label }) => label).join("| ");
const boolean = user.customBooleanFieldAnswers.find(({id: qId}) => qId === value)
if (boolean && boolean.hasAnswered) userData[key] = boolean.answer;
});
return userData;
}

getRequiredClientFields() {
return this.getAsArray('requiredClientFields');
}
Expand Down

0 comments on commit 3a2c9bf

Please sign in to comment.