Getting multiple value in product_category to segregate the purchase made

Jaikrish
Visitor
Jaikrish

Team,

we have a medical purchase site where we used to capture all the medical products detail purchased. So, all the data layer has been created as expected and firing fine. However, we used to find difficulties to categories the product from the product ID. Each product has there own product ID assigned and that should be captured in "product_id" UDO variable at the end of the purchase but not the "product_category" value eventually. So, I have used look up extension to assign the value for the "product_category" variable. Like, look up for "product_id" is 525 and output would be "therapetic" under "product_category" variable. it goes smooth untill cusotmer purchased one product from the same category since I have used the condition. However, we are not getting the multiple value in "product_category" varibale when customer purchase in different categories with multiple "product_id". Like, if the "product_id" value is ["522", "422"] and I am getting only one "product_category" value, another one is not captured.

May be the method I have used to get the value for "product_category" is wrong. Is there any other way to get the multiple value for the "product_category" variable. So that it can help us to categaries the product accordiongly.

Please let me know for any other more information.

Thank you!

5 REPLIES 5

Getting multiple value in product_category to segregate the purchase made

dsavvy
Visitor
dsavvy Visitor

So product_id is already being populated int he datalayer?

And you want an array in product_category to be generated to mirror the product_id,


product_id :     ["100",       "200",    "300",     "200"  ]
product_cat:    ["cat_a",   "cat_b",  "cat_c",  "cat_b" ]

using the lookup table will only work for one value and will not generate an array for you.

You will probably need to create a JS extension to do this, with your own mapping table.

So the quickesst solution would be to create your own mapping table, something like this,

var map = { 
key1: "v1", 
key2: "v2",
key3: "v3", 
key4: "v4", 
key5: "v5", 
key6: "v6", 
key7: "v7", 
key8: "v8" 
}



then create a JS function to loop through the keys to grab them and put them into an array, i have written something like this:

var product_id = ["key2","key6","key3"];  //lets assume you are using product_id from the datalayer
//we are then going to loop through this productid array and grab the correct keys and values
var product_category = [];
var arrayLength = product_id.length;
for (var i = 0; i < arrayLength; i++) {
product_category.push(map[product_id[i]]);
}

and then here we will output the generated array which you will then push back into the datalayer
console.log(product_category);   //you should see ["v2", "v6", "v3"]


 

 

This is just for deomnstation on how you can use JS extension to make your array for product category, you should be able to test this method in your console and see how it works...
But you may need to adapt the map to accomodate your productid etc.. but this should be a good start for you in understanding how to generate a dynamic list array,

Damian Savvides

Getting multiple value in product_category to segregate the purchase made

Jaikrish
Visitor
Jaikrish

thanks much for your explanation. I will try to understand the part you mentioned below and will execute the same to get the product_variable.

Getting multiple value in product_category to segregate the purchase made

jayap3
Visitor
jayap3

I think we can accomblish in our tealium features.

Getting multiple value in product_category to segregate the purchase made

Jaikrish
Visitor
Jaikrish

Hi @dsavvy ,

Thanks so much for the below explanation. It works and I can able to see the multiple value (array Value) passing in to my respective variable on the mentioned code. something I have changed the code below respective to my question as requested.

var map = {
1005: "Men",
1006: "Men",
4569: "women",
8745: "women",
} // Mapped all my product_ID to the respective category

var product_id = utag_data.product_id; // Dymnamically I am getting data from the product_id at the end of the purchase.

var product_category = [];
var arrayLength = product_id.length;
for (var i = 0; i < arrayLength; i++) {
product_category.push(map[product_id[i]]);
}

console.log(product_category); // Here I can able to see the respective category which I am geeting from product_id. getting something like this - ["women", "Men"]

Still no vaule for "utag_data.product_category" after purchase made but seeing the data when I console the code.

However, the same is not passing to my respective data layer which is "product_category" so eventually category value is not passing at the end of the purchase made. Therefore, how do we map those array value in to my own daya layer (product_category).

Could you please assist me to map those value getting from the console to my respective data layer. So that it would helpful for me to categories the product. Please let me know if any.

Thank you!

Getting multiple value in product_category to segregate the purchase made

Jaikrish
Visitor
Jaikrish

Hi @dsavvy ,

I was trying to get product_category value assigned to my local data layer in different ways and finally i have accomblished the same.Thanks much for your time.

Regards,
Jay.