Target Audience Based on Cookie Value

marshallsewell 16-05-2017

Is there currently no way within Target to build an audience based on a cookie value?  So if we have a cookie that denotes whether they are a customer or not, we can't build an audience and target a test based on that?  If not, are there plans to add this functionality?  Both Google Optimize and Optimizely offer this functionality out of the box and is very beneficial in testing.  Thanks

Accepted Solutions (1)

Accepted Solutions (1)

bhawkins 17-05-2017

Another option is this:

parametersFunction: function() {
    function readCookie(name) {
        var nameEQ = name + "\x3d";
        var ca = document.cookie.split(";");
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == " ") c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)
        }
        return null
    }
    return "parameter" + readCookie("cookie_name");
}

 

This code just needs to be added parameters section of your mbox.js library.  Just update the cookie name in bold and this will automatically pass the cookie value to your mbox as an mbox parameter.  

Answers (6)

Answers (6)

ParitMittal 17-05-2017

Hi,

The only way to achieve the above use case is to create a profile script to retrieve & validate a cookie value using the method : mboxFactoryDefault.getCookieManager()​.getCookie("name")  and then create an audience based on that profile script.

For more information , Please see:

https://marketing.adobe.com/resources/help/en_US/target/target/r_variables_profiles_parameters_metho...

https://marketing.adobe.com/resources/help/en_US/target/target/c_script_profile_attributes.html

Regards

Parit Mittal

fabiant29754507 18-08-2017

Hi Parit,

thanks for the answer! I tried that but it seems like this function is outdated for at.js - at least Target can't run the script because it's invalid. Also the Adobe Help states that "These functions are available when implementing with mbox.js. If you are using at.js, these methods do not apply."

Do you know if there's a similar function for at.js? I wasn't able to find one.

In the meantime I'm using the mbox parameter approach also mentioned in this thread.

Best,

Fabian

amardeeps255847 09-08-2017

Is it the same if we are using at.js?  We just add this:

parametersFunction: function() {

    function readCookie(name) {

        var nameEQ = name + "\x3d";

        var ca = document.cookie.split(";");

        for (var i = 0; i < ca.length; i++) {

            var c = ca[i];

            while (c.charAt(0) == " ") c = c.substring(1, c.length);

            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length)

        }

        return null

    }

    return "parameter" + readCookie("cookie_name");

}

ryanr79035901
Employee
17-05-2017

Hi Marshall,

As bhawkins showed above you can modify your mbox.js or at.js to pick up a cookie(s) value and pass it into Target for defining audiences off of. Target doesn't pick up your sites cookies by default, which I'm betting is by design for privacy reasons. However, you have the abilty to implement Target so it always see's certain cookies.