Skip to content

Commit

Permalink
Merge pull request #29 from stape-io/added-missing-user-data-fields
Browse files Browse the repository at this point in the history
Added missing userData fields
  • Loading branch information
Bukashk0zzz authored Jul 4, 2024
2 parents 21d023b + 333f8ac commit 857f5de
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 16 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: b0cb2a6c643dd0b5baea1db3d382a1f7bb3bb546
changeNotes: Added missing userData fields.
- sha: 1b2f1fc426f1a7265d462007563cf0861d6600e8
changeNotes: Fix useOptimisticScenario.
- sha: 08869b97a6326f7168c571d5729e820e8753ad28
Expand Down
48 changes: 41 additions & 7 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ function mapEvent(eventData, data) {
event_source_id: data.pixelId,
data: [mappedData],
};

if (data.testEventCode) {
requestData.test_event_code = data.testEventCode;
}
const testEventCode = eventData.test_event_code || data.testEventCode;
if (testEventCode) requestData.test_event_code = testEventCode;

return requestData;
}
Expand Down Expand Up @@ -263,11 +261,15 @@ function addPropertiesData(eventData, mappedData) {
}

function addUserData(eventData, mappedData, eventSource) {
let userEventData = {};
mappedData.user = {};

let userEventData = {};
let address = {};
if (getType(eventData.user_data) === 'object') {
userEventData = eventData.user_data || eventData.user_properties || eventData.user;
userEventData = eventData.user_data;
const addressType = getType(userEventData.address);
if (addressType === 'object' || addressType === 'array') {
address = userEventData.address[0] || userEventData.address;
}
}

if (eventData.email) mappedData.user.email = eventData.email;
Expand All @@ -280,6 +282,38 @@ function addUserData(eventData, mappedData, eventSource) {
else if (userEventData.phone) mappedData.user.phone = userEventData.phone;
else if (userEventData.phone_number) mappedData.user.phone = userEventData.phone_number;

if (eventData.lastName) mappedData.user.last_name = eventData.lastName;
else if (eventData.LastName) mappedData.user.last_name = eventData.LastName;
else if (eventData.nameLast) mappedData.user.last_name = eventData.nameLast;
else if (eventData.last_name) mappedData.user.last_name = eventData.last_name;
else if (userEventData.last_name) mappedData.user.last_name = userEventData.last_name;
else if (address.last_name) mappedData.user.last_name = address.last_name;

if (eventData.firstName) mappedData.user.first_name = eventData.firstName;
else if (eventData.FirstName) mappedData.user.first_name = eventData.FirstName;
else if (eventData.nameFirst) mappedData.user.first_name = eventData.nameFirst;
else if (eventData.first_name) mappedData.user.first_name = eventData.first_name;
else if (userEventData.first_name) mappedData.user.first_name = userEventData.first_name;
else if (address.first_name) mappedData.user.first_name = address.first_name;

if (eventData.city) mappedData.user.city = eventData.city;
else if (address.city) mappedData.user.city = address.city;

if (eventData.state) mappedData.user.state = eventData.state;
else if (eventData.region) mappedData.user.state = eventData.region;
else if (userEventData.region) mappedData.user.state = userEventData.region;
else if (address.region) mappedData.user.state = address.region;

if (eventData.zip) mappedData.user.zip_code = eventData.zip;
else if (eventData.postal_code) mappedData.user.zip_code = eventData.postal_code;
else if (userEventData.postal_code) mappedData.user.zip_code = userEventData.postal_code;
else if (address.postal_code) mappedData.user.zip_code = address.postal_code;

if (eventData.countryCode) mappedData.user.country = eventData.countryCode;
else if (eventData.country) mappedData.user.country = eventData.country;
else if (userEventData.country) mappedData.user.country = userEventData.country;
else if (address.country) mappedData.user.country = address.country;

if (eventSource === 'web') {
if (ttclid) mappedData.user.ttclid = ttclid;
else if (eventData.ttclid) mappedData.user.ttclid = eventData.ttclid;
Expand Down
76 changes: 67 additions & 9 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,30 @@ ___TEMPLATE_PARAMETERS___
{
"value": "att_status",
"displayValue": "ATT Status"
},
{
"value": "first_name",
"displayValue": "First Name"
},
{
"value": "last_name",
"displayValue": "Last Name"
},
{
"value": "city",
"displayValue": "City"
},
{
"value": "state",
"displayValue": "State"
},
{
"value": "country",
"displayValue": "Country"
},
{
"value": "zip_code",
"displayValue": "Zip"
}
]
},
Expand Down Expand Up @@ -565,7 +589,6 @@ ___TEMPLATE_PARAMETERS___
{
"type": "RADIO",
"name": "logType",
"displayName": "debug",
"radioItems": [
{
"value": "no",
Expand All @@ -580,7 +603,8 @@ ___TEMPLATE_PARAMETERS___
"displayValue": "Always log to console"
}
],
"simpleValueType": true
"simpleValueType": true,
"defaultValue": "debug"
}
]
}
Expand Down Expand Up @@ -748,10 +772,8 @@ function mapEvent(eventData, data) {
event_source_id: data.pixelId,
data: [mappedData],
};

if (data.testEventCode) {
requestData.test_event_code = data.testEventCode;
}
const testEventCode = eventData.test_event_code || data.testEventCode;
if (testEventCode) requestData.test_event_code = testEventCode;

return requestData;
}
Expand Down Expand Up @@ -854,11 +876,15 @@ function addPropertiesData(eventData, mappedData) {
}

function addUserData(eventData, mappedData, eventSource) {
let userEventData = {};
mappedData.user = {};

let userEventData = {};
let address = {};
if (getType(eventData.user_data) === 'object') {
userEventData = eventData.user_data || eventData.user_properties || eventData.user;
userEventData = eventData.user_data;
const addressType = getType(userEventData.address);
if (addressType === 'object' || addressType === 'array') {
address = userEventData.address[0] || userEventData.address;
}
}

if (eventData.email) mappedData.user.email = eventData.email;
Expand All @@ -871,6 +897,38 @@ function addUserData(eventData, mappedData, eventSource) {
else if (userEventData.phone) mappedData.user.phone = userEventData.phone;
else if (userEventData.phone_number) mappedData.user.phone = userEventData.phone_number;

if (eventData.lastName) mappedData.user.last_name = eventData.lastName;
else if (eventData.LastName) mappedData.user.last_name = eventData.LastName;
else if (eventData.nameLast) mappedData.user.last_name = eventData.nameLast;
else if (eventData.last_name) mappedData.user.last_name = eventData.last_name;
else if (userEventData.last_name) mappedData.user.last_name = userEventData.last_name;
else if (address.last_name) mappedData.user.last_name = address.last_name;

if (eventData.firstName) mappedData.user.first_name = eventData.firstName;
else if (eventData.FirstName) mappedData.user.first_name = eventData.FirstName;
else if (eventData.nameFirst) mappedData.user.first_name = eventData.nameFirst;
else if (eventData.first_name) mappedData.user.first_name = eventData.first_name;
else if (userEventData.first_name) mappedData.user.first_name = userEventData.first_name;
else if (address.first_name) mappedData.user.first_name = address.first_name;

if (eventData.city) mappedData.user.city = eventData.city;
else if (address.city) mappedData.user.city = address.city;

if (eventData.state) mappedData.user.state = eventData.state;
else if (eventData.region) mappedData.user.state = eventData.region;
else if (userEventData.region) mappedData.user.state = userEventData.region;
else if (address.region) mappedData.user.state = address.region;

if (eventData.zip) mappedData.user.zip_code = eventData.zip;
else if (eventData.postal_code) mappedData.user.zip_code = eventData.postal_code;
else if (userEventData.postal_code) mappedData.user.zip_code = userEventData.postal_code;
else if (address.postal_code) mappedData.user.zip_code = address.postal_code;

if (eventData.countryCode) mappedData.user.country = eventData.countryCode;
else if (eventData.country) mappedData.user.country = eventData.country;
else if (userEventData.country) mappedData.user.country = userEventData.country;
else if (address.country) mappedData.user.country = address.country;

if (eventSource === 'web') {
if (ttclid) mappedData.user.ttclid = ttclid;
else if (eventData.ttclid) mappedData.user.ttclid = eventData.ttclid;
Expand Down

0 comments on commit 857f5de

Please sign in to comment.