Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

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.

?

 

 

14 REPLIES 14

Cookie value set from Audience Stream Enriched data layer

Tealium Employee

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

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

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?

Cookie value set from Audience Stream Enriched data layer

Tealium Employee

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.

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

Thanks Dan!

 

Makes sense.

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

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

Cookie value set from Audience Stream Enriched data layer

Tealium Employee

@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.

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

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

Cookie value set from Audience Stream Enriched data layer

Tealium Employee
Not at all, you see the light!

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

Hi Dan,

I am trying to do the same thing - write the badge names onto a cookie.  I have saved the exact code here in an extension and variously scoped it to All tags, Pre Loader and Tealium Collect tags but the logs do not appear at all.  Can you suggest any possible reason?

Thanks a lot,
Regards,
Sujani

Cookie value set from Audience Stream Enriched data layer

Tealium Employee

@sujani_koya the only thing I can think of is that within the Tealium Collect tag you have Data Enrichment set to "none". Change this to "frequent" and that will allow the AudienceStream attributes to be pulled back into the web page.

Second, please be sure to update to the latest version of the Collect tag. If you're unfamiliar with doing so I'd suggest following these directions.

I hope this helps!

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

Thanks Dan!  Both these steps helped.  Seeing the logs now :) 

Cookie value set from Audience Stream Enriched data layer

Moderator
Moderator

OOOOooooo.... I'd accept @dan_george's reply as a solution @sujani_koya! #JustSaying

#hugs

If you liked it then you should have put a kudo on it!

Cookie value set from Audience Stream Enriched data layer

Gold Contributor
Gold Contributor

Unfortunately I am not the original poster so can't accept as the solution! 

Cookie value set from Audience Stream Enriched data layer

Moderator
Moderator

Thank you for trying @sujani_koya! #EvenMoreHugs!!!

If you liked it then you should have put a kudo on it!
Public