Skip to content

Commit

Permalink
Content category hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
kHorozhanov committed Nov 27, 2023
1 parent 3a10a3c commit 2617736
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
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

0 comments on commit 2617736

Please sign in to comment.