Skip to content

Commit

Permalink
Merge pull request #15 from stape-io/fix-falsy-customer-identifiers
Browse files Browse the repository at this point in the history
Fix falsy customer identifiers
  • Loading branch information
Bukashk0zzz authored Mar 13, 2024
2 parents 058d011 + 10738b2 commit 65b8721
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
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

0 comments on commit 65b8721

Please sign in to comment.