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

Content category hierarchy #39

Closed
wants to merge 2 commits into from
Closed
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: 2617736a12ae54a9332c218c2e5c50996ea93149
changeNotes: Added support for multiple item categories.
- sha: 44b60bf1f406af83ee98144b192d43b6c052308c
changeNotes: Version update, Business messenger support
- sha: cddd6fe15a357fc2e8e7bc70d5d5b5f026c83795
Expand Down
14 changes: 12 additions & 2 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function addEcommerceData(eventData, mappedData) {

if (!eventData.items[1]) {
if (eventData.items[0].item_name) mappedData.custom_data.content_name = eventData.items[0].item_name;
if (eventData.items[0].item_category) mappedData.custom_data.content_category = eventData.items[0].item_category;
if (eventData.items[0].item_category) mappedData.custom_data.content_category = mapItemCategoriesToContentCategory(eventData.items[0]);

if (eventData.items[0].price) {
mappedData.custom_data.value = eventData.items[0].quantity
Expand All @@ -384,7 +384,7 @@ function addEcommerceData(eventData, mappedData) {
if (d.item_name) content.title = d.item_name;
if (d.item_brand) content.brand = d.item_brand;
if (d.quantity) content.quantity = d.quantity;
if (d.item_category) content.category = d.item_category;
if (d.item_category) content.category = mapItemCategoriesToContentCategory(d);

if (d.price) {
content.item_price = makeNumber(d.price);
Expand Down Expand Up @@ -601,6 +601,16 @@ function enhanceEventData(userData) {
return userData;
}

function mapItemCategoriesToContentCategory(item) {
const categories = [item.item_category];
let categoryLevel = 2;
while (item['item_category' + categoryLevel]) {
categories.push(item['item_category' + categoryLevel]);
categoryLevel++;
}
return categories.filter(category => !!category).join(' > ');
}

function determinateIsLoggingEnabled() {
const containerVersion = getContainerVersion();
const isDebug = !!(
Expand Down
14 changes: 12 additions & 2 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ function addEcommerceData(eventData, mappedData) {

if (!eventData.items[1]) {
if (eventData.items[0].item_name) mappedData.custom_data.content_name = eventData.items[0].item_name;
if (eventData.items[0].item_category) mappedData.custom_data.content_category = eventData.items[0].item_category;
if (eventData.items[0].item_category) mappedData.custom_data.content_category = mapItemCategoriesToContentCategory(eventData.items[0]);

if (eventData.items[0].price) {
mappedData.custom_data.value = eventData.items[0].quantity
Expand All @@ -1043,7 +1043,7 @@ function addEcommerceData(eventData, mappedData) {
if (d.item_name) content.title = d.item_name;
if (d.item_brand) content.brand = d.item_brand;
if (d.quantity) content.quantity = d.quantity;
if (d.item_category) content.category = d.item_category;
if (d.item_category) content.category = mapItemCategoriesToContentCategory(d);

if (d.price) {
content.item_price = makeNumber(d.price);
Expand Down Expand Up @@ -1260,6 +1260,16 @@ function enhanceEventData(userData) {
return userData;
}

function mapItemCategoriesToContentCategory(item) {
const categories = [item.item_category];
let categoryLevel = 2;
while (item['item_category' + categoryLevel]) {
categories.push(item['item_category' + categoryLevel]);
categoryLevel++;
}
return categories.filter(category => !!category).join(' > ');
}

function determinateIsLoggingEnabled() {
const containerVersion = getContainerVersion();
const isDebug = !!(
Expand Down
Loading