- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
07-23-2019 03:22 AM
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!
Solved! Go to Solution.
07-24-2019 05:10 AM
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,
07-24-2019 05:41 AM
07-26-2019 03:36 AM - edited 07-26-2019 03:38 AM
07-30-2019 10:00 PM
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!
07-31-2019 02:29 AM
07-22-2021 08:40 AM
Copyright All Rights Reserved © 2008-2023