Reply
Highlighted
Visitor
Posts: 72
Registered: ‎05-11-2016
Accepted Solution

Cookie value set from Audience Stream Enriched data layer

Hello,

 

How do I take data enriched data layer sources (i.e. badges from Audience Stream) and write a pipe delimited list of the badge IDs to a 1st party cookie?

 

I found the article on visitor service cookie callbacks here:

https://community.tealiumiq.com/t5/AudienceStream/How-to-Next-Page-Personalization-leveraging-Tealiu...

 

But want to make sure I'm understanding correctly.  Also, I'd like to have the call back happen on every pageload/server call (any issues with that from a technical or billing perspective?)

 

Are below steps correct:

1. add badge(s) as enriched data layer object.

2. use code below in a pre-loader javascript call:

 

window.tealium_enrichment = function(data) {
console.log("Visitor Service Cookie Callback");
var page = utag.data.page_name;

var dest = data['properties']['BadgeID1'] || "" data['properties']['BadgeID2'] || ""

if (dest !== "") {
utag.loader.SC("myCookieName", dest);
}
};

 

Then publish and test.

?

 

 

Tealium Employee
Posts: 581
Registered: ‎09-01-2015

Re: Cookie value set from Audience Stream Enriched data layer

Hi @Michael_Kim_shc

 

Do you want to set all badges/audiences, or just a select few badges/audiences? Let me know and we'll guide on the best script to use.

 

Doing the callback on every event is not an issue, meaning it will not effect your billing. The only extra "cost" is the loading and running (very little in the grand scheme of things) of the script.

 

Also, that callback should be scoped to the Tealium Collect tag.

 

Cheers,

-Dan

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better!

Visitor
Posts: 72
Registered: ‎05-11-2016

Re: Cookie value set from Audience Stream Enriched data layer

What up @dan_george!  Thx for response.. seems like you're the local forum crawler?

 

I'm not sure if i'll be doing all badges/audiences - might depend on how many we end up with.  Can you share both options (selected badge/audiences and all badges/audiences) with brief pros/cons?

Reply
0 Kudos
Tealium Employee
Posts: 581
Registered: ‎09-01-2015

Re: Cookie value set from Audience Stream Enriched data layer

[ Edited ]

This will add all badges to a cookie.

 

window.tealium_enrichment = function(data) {
   //console.log("Visitor Service Cookie Callback");
   var badges="";
   for(i in utag.data){
      if(i.indexOf("va.badges")==0){
         //console.log(i+" = "+utag.data[i]);
         badges+=i.replace("va.badges.","")+"|";
      }
   }
   if(badges!=""){
      utag.loader.SC("myCookieName", badges);
   }
};

 

The end results will be cookie "myCookieName" with a value of "5082|5101|5203|5465|". 

 

Adding audiences to this code is very simple.

 

The pro of doing this is it doesn't have to be maintained/updated each time a new badge/audience is added. It will just automatically add your new badge ID and audience name.

 

The con of doing this is that if you have a lot of badges and audiences then the cookie could potentially get rather large.

 

The example above can easily be edited to look for specific badge/audience IDs if need be.

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better!

Visitor
Posts: 72
Registered: ‎05-11-2016

Re: Cookie value set from Audience Stream Enriched data layer

Thanks Dan!

 

Makes sense.

Reply
0 Kudos
Visitor
Posts: 72
Registered: ‎05-11-2016

Re: Cookie value set from Audience Stream Enriched data layer

@dan_george Hey Dan!  What if I want to set the values to a varaible in Local Storage instead of cookies?

Reply
0 Kudos
Tealium Employee
Posts: 581
Registered: ‎09-01-2015

Re: Cookie value set from Audience Stream Enriched data layer

@Michael_Kim_shc

 

Then you can change:

utag.loader.SC("myCookieName", badges);

 

To be the logic to save to localStorage.

 

The basic structure of what you need is stated above, and you can edit as you see fit.

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better!

Reply
0 Kudos
Visitor
Posts: 72
Registered: ‎05-11-2016

Re: Cookie value set from Audience Stream Enriched data layer

And now I see the silliness of my question.  Thanks:)

Tealium Employee
Posts: 581
Registered: ‎09-01-2015

Re: Cookie value set from Audience Stream Enriched data layer

Not at all, you see the light!

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better!