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

Commit

Permalink
Merge pull request #803 from B77Mills/addLabel
Browse files Browse the repository at this point in the history
Add getGTMUserData() & gtmUserFields prop to identityX config.
  • Loading branch information
brandonbk authored Sep 28, 2023
2 parents c840d48 + 19900ac commit b61115b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/marko-web-identity-x/api/fragments/active-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fragment ActiveUserFragment on AppUser {
}) {
id
hasAnswered
answers { id externalIdentifier writeInValue }
answers { id label externalIdentifier writeInValue }
field {
id
label
Expand Down
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 = {},
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');
}

getGTMUserData(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 }) => id === value);
if (select && select.answers.length) userData[key] = select.answers.map(({ label }) => label).join('|');
const boolean = user.customBooleanFieldAnswers.find(({ id }) => id === value);
if (boolean && boolean.hasAnswered) userData[key] = boolean.answer;
});
return userData;
}

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

0 comments on commit b61115b

Please sign in to comment.