Expand my Community achievements bar.

SOLVED

Target Audience Based on Cookie Value

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Level 2

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.  

View solution in original post

7 Replies

Avatar

Level 10

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

Avatar

Level 1

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

Avatar

Correct answer by
Level 2

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.  

Avatar

Employee Advisor

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.

Avatar

Level 1

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");

}

Avatar

Level 2

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

Avatar

Level 1

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