Reply
Visitor
Posts: 10
Registered: ‎08-25-2017

Problem with cookie length

Hi guys.

I'm using the channel extention and I'm experiencing a problem with the channel_flow cookie.

seemes the problem is with some versions of IE since those browsers allow longer cookies than others.

is there a way to limit the cookie length?

The problem is with my internetbanking provider, the will not allow the user to make any transactions if they have a cookie that exeeds 4097 bytes.

Reply
0 Kudos
Highlighted
VIP
Posts: 215
Registered: ‎01-04-2016

Re: Problem with cookie length

[ Edited ]

Growing cookie length is an important issue - I can only recommend extensive testing and monitoring. I inherited an implementation which included a custom JS extension (homemade channel manager) which allowed unchecked cookie growth and it festered until there were resulting server issues (http 503 errors).  We had to take two measures, 1) extend cookie length accepted by the server (short term fix) and 2) update the extension to truncate it to only 200 bytes or so.  

 

As they say, with great power comes responsibility - be vigilant on this one! 

 

Also of concern would be if the target system to receive the channel manager cookie value can accept such a large unchecked length.

 

Looking forward to your updates, @Bknapstad !

Reply
0 Kudos
Visitor
Posts: 10
Registered: ‎08-25-2017

Re: Problem with cookie length

Thank you for your response.

So this is what I've been thinking,

It's just this one cookie or potentaly cookies from this extention that is the problem, and I kind of want to keep the functionality of that cookie. So I'll have to find a way to turnicate the cookie while keeping it's core function. This is what the cookie lookslike:

channel_flow=channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256,channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256,channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256,channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256,channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256,channel1|affiliate|1358975968083,channel2|displayads|1358975970419,channel3|sponsorship|1358975973256

it contains the channel, the type of traffic and a timestamp in milliseconds. The most recent channel is at the end of the string. so if I want to turnicate it I want to keep the most recent data. Also this cookie never needs to be 4000 long with an average of 50 on each channel that would be the 80 most recent channels. I'll limit this to 1000 chars.

Heres the code I've made so far (sorry the variablenames are in Norwegian):

function smaakaker(){
let smaakaker = document.cookie.split(";"); //splits the cookies in an array
for(i=0; i<smaakaker.length+1; i++){ //loops over the cookies
    if(smaakaker[i].length > 1000){ //any cookie over 1000 in length
        let nykake = smaakaker[i].trim(); //trim any whitespace
        let kakestart=nykake.slice(0,nykake.indexOf("=")+1); //fetch the start of the cookie
        if (kakestart.includes("channel")){ // check if the cookie is from the channel extention
            while(nykake.length > 1000){ 
                nykake = nykake.slice(nykake.indexOf(",")+1); // remove the oldest entry
            }
    
            nykake = kakestart+nykake+";max-age=5184000";
            document.cookie = nykake; // set the turnicated cookie

        }
        
    }
}
}

Now my JS is not the best, but is this a valid solution to the problem?

 

 

Reply
0 Kudos
Tealium Employee
Posts: 23
Registered: ‎07-11-2017

Re: Problem with cookie length

Hi @Bknapstad 

I can simplify that code for you by taking advantage of built-in utag utilities

var flow = utag.loader.RC("channel_flow");
while (flow.length > 1000) {
  flow = flow.split(",").slice(1).join(",");
}
utag.loader.SC("channel_flow", flow);

Hope that helps!

Reply
0 Kudos