Categories the value in product category and gonna create audience accordingly

Jaikrish
Visitor
Jaikrish

Team,

I am trying to categories the product category from the product ID when customer made the purchase on the site. Since we haven't pass the value to the product category at the end of the purchade made. So, I have used look up entension on the "product_id" and assign the output in to "product_category". Like, look up for "product_id" is 1008 and output would be "Men" under "product_category" variable. Based on that I was assigning the value for the product category. However, when customer order two product from different category, let say Men and Women, then only one "product_category" value getting assign and other one is missing.

So, please suggest me the better plan to get the baule for the product_category when customer made the purchase on the different catregories. Therefore, I can laos schedule my audience accorindly whoeever is purchased on the different section.

Please let me know if any.

Thank you!

6 REPLIES 6
Highlighted

Categories the value in product category and gonna create audience accordingly

Tealium Employee

Hi Jay
My understanding of what you are asking for here is;

In your Data Layer on your order confirmation page, you have something like this

...
"product_id":["id1","id2","id3"],
"product_quantity":["1","2","1"],
...

You wish to translate the product ids to product categories using an iQ extension, and in AudienceStream you wish to have a visitor lifetime tally of the number of times the visitor has purchased each product category.

Is my understanding correct?

Categories the value in product category and gonna create audience accordingly

Jaikrish
Visitor
Jaikrish

Hi Mark,

Thanks for your time on this post. Yes, you are right, let me try to explain briefly one more time.

I am trying to assign the "product_category" name from the "product_id" value whatever it captured at the end of the purchase but I get only one name and rest is not capturing as per the look up extension method. Though, I should capture all the category name from the "product_id" which should look like product_category:["Men", "Women"]. However, I am getting only one name on the "prouct_category" variable at the end of the purchase as mentioned below.

product_id:["1008", "3352"]

product_category:"Men"

Please assit me to capture all the category name under the "product_category" data layer from the "product_id" data layer at the end of the purchase. Therefore, I can segregate the visitor who have purchased on the different category based up on the value getting from "product_category" value. Please let me know for any other information.

Thank much!

 

Categories the value in product category and gonna create audience accordingly

Tealium Employee

Hi @Jaikrish 

This is both an iQ question and an AS question.

iQ - the lookup extension is designed for cases where the input to lookup on is a single item.  It is not designed to loop through an array of items and lookup for each of them.  So you'd need to write that JS yourself.

Here's a starter - you'll need to add some checking to that to make sure the input is indeed an Array

 

//looks up for each item in the source array
//and outputs into the destination data variable specified

//configure here
var source = b.product_id;
var nameOfDestinationVariable = 'product_category';
var lookup = [
{'1': 'men'},
{'2': 'men'},
{'3': 'women'},
{'4': 'women'}
];

//don't change anything below here
var destination = [];
if (typeof source == 'undefined')
    return;
for (var h = 0; h < source.length; h++) {
    var matched = false;
    for (var i = 0; i < lookup.length; i++) {
        for (var f in lookup[i]) {
            if (source[h] == f) {
                destination.push(lookup[i][f]);
                matched = true;
            }
        }
        if (matched)
            break;
    }
    if (!matched)
        destination.push('');
}
b[nameOfDestinationVariable] = destination;

If you scope a JS extension like that to the collect tag, you will get what you need.

 

I also notice this other TLC post, which seems very similar - https://community.tealiumiq.com/t5/Tealium-iQ-Tag-Management/Getting-multiple-value-in-product-categ...

In AS, you need to do a couple of things;

1. Add an event variable (array of strings) to hold the product_category if not already there.

2. Add an event variable (array of numbers) to hold the product_quantity if not already there 

3. Add a Tally (visit or visit scoped, it doesn't matter) to hold the current order temporarily.  Set this using the enrichment "Set Tally by corresponding arrays".  In there, select the product_category as the first input to the enrichment and product_quantity to the second.

4. Add a second Tally, visitor scoped.  Add an enrichment to "Increment Tally by Tally" based on the temporary tally in 3 above.  However, use a rule here to only do this when it is an order confirmation event.

Categories the value in product category and gonna create audience accordingly

Jaikrish
Visitor
Jaikrish

Hi Mark,

Thanks so much. I have applied the code mentioned below on my "Javascript Code" extenion in Tealium IQ with Tealium collect tag scope specified.

Moreover, on the mentioned code I have changed the look up array to look for "product_id" on the site. I guess that the way it should look up as a array and pust it the value. Am I correct here? please correct me if I am wrong. Changed something like this and tested. Even I can see the same result without modifying any changes on the code.

var lookup = [
{'1008': 'men'},
{'1009': 'men'},
{'3256': 'women'},
{'43257': 'women'}
];

Now I can see that the "product_category" data layer varibale is an array but not getting a value whenever the site loaded with the product but I can see the "product_id" value perfectly . I am trying to debug using the "UDO Debugger" and see "product_category:Array[0]" for the category varibale. Please correct me if I am wrong and let me know for any other information.

In regards to the AS, I will apply the mentioned steps and kep you posted.

Thanks much!

Categories the value in product category and gonna create audience accordingly

Tealium Employee

@Jaikrish The extension is scoped to the collect tag, which means it only affects that tag's data layer.  This is best practice.  It does mean that you need to look at the data in the collect tag to see the result of the extension.  The easiest place to do that is in AudienceStream trace.  Expand the incoming event and it will show you the data layer that UDH received.

I'd suggest if you are having issues still, you reach out to support@tealium.com, giving them steps to reproduce, so that they can debug your issue for you.

Categories the value in product category and gonna create audience accordingly

Jaikrish
Visitor
Jaikrish

thank you so muich for all your explanation.