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

Fix falsy customer identifiers #15

Merged
merged 2 commits into from
Mar 13, 2024
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
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
homepage: "https://stape.io/"
versions:
- sha: 6be12bc9a7dfd5d6a3a6a8865fe3131a2e348d98
changeNotes: Fix falsy customer identifiers.
- sha: 6955b64a199a667d6af5112fd2d4f1e6b4d15b90
changeNotes: Added support for external_attribution_data.
- sha: 896519ddfb566753a546dcc7fe4d105155b4ee21
Expand Down
21 changes: 12 additions & 9 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ function addUserIdentifiers(eventData, mappedData) {
let mobileId;
let thirdPartyUserId;
let addressInfo;
let userIdentifiersMapped;
let userIdentifiersMapped = [];
let userEventData = {};
let usedIdentifiers = [];

Expand All @@ -388,13 +388,16 @@ function addUserIdentifiers(eventData, mappedData) {
let userIdentifiers = [];

data.userDataList.forEach((d) => {
let identifier = {};

identifier[d.name] = hashData(d.name, d.value);
identifier['userIdentifierSource'] = d.userIdentifierSource;

userIdentifiers.push(identifier);
usedIdentifiers.push(d.name);
const valueType = getType(d.value);
const isValidValue = ['undefined', 'null'].indexOf(valueType) === -1 && d.value !== '';
if(isValidValue) {
let identifier = {};
identifier[d.name] = hashData(d.name, d.value);
identifier['userIdentifierSource'] = d.userIdentifierSource;

userIdentifiers.push(identifier);
usedIdentifiers.push(d.name);
}
});

userIdentifiersMapped = userIdentifiers;
Expand Down Expand Up @@ -455,7 +458,7 @@ function addUserIdentifiers(eventData, mappedData) {
});
}

if (userIdentifiersMapped) {
if (userIdentifiersMapped.length) {
mappedData.userIdentifiers = userIdentifiersMapped;
}

Expand Down
21 changes: 12 additions & 9 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function addUserIdentifiers(eventData, mappedData) {
let mobileId;
let thirdPartyUserId;
let addressInfo;
let userIdentifiersMapped;
let userIdentifiersMapped = [];
let userEventData = {};
let usedIdentifiers = [];

Expand All @@ -967,13 +967,16 @@ function addUserIdentifiers(eventData, mappedData) {
let userIdentifiers = [];

data.userDataList.forEach((d) => {
let identifier = {};

identifier[d.name] = hashData(d.name, d.value);
identifier['userIdentifierSource'] = d.userIdentifierSource;

userIdentifiers.push(identifier);
usedIdentifiers.push(d.name);
const valueType = getType(d.value);
const isValidValue = ['undefined', 'null'].indexOf(valueType) === -1 && d.value !== '';
if(isValidValue) {
let identifier = {};
identifier[d.name] = hashData(d.name, d.value);
identifier['userIdentifierSource'] = d.userIdentifierSource;

userIdentifiers.push(identifier);
usedIdentifiers.push(d.name);
}
});

userIdentifiersMapped = userIdentifiers;
Expand Down Expand Up @@ -1034,7 +1037,7 @@ function addUserIdentifiers(eventData, mappedData) {
});
}

if (userIdentifiersMapped) {
if (userIdentifiersMapped.length) {
mappedData.userIdentifiers = userIdentifiersMapped;
}

Expand Down
Loading