Target Audience Based on Cookie Value | Community
Skip to main content
May 16, 2017
Solved

Target Audience Based on Cookie Value

  • May 16, 2017
  • 7 replies
  • 11152 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by bhawkins34

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.  

7 replies

ParitMittal
Level 10
May 17, 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_methods.html

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

Regards

Parit Mittal

May 17, 2017

So is that function something that needs to be included in our mbox.js file during implementation?

bhawkins34Accepted solution
Level 3
May 17, 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.  

Adobe Employee
May 17, 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.

August 9, 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");

}

fabiant29754507
Level 2
August 18, 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

DerRudi
July 19, 2018

Can you please provide the entire code for the profile script? If I use it as it is Target reports a runtime error.