Launch an activity if a cookie is in the page with mbox.js | Community
Skip to main content
November 30, 2017

Launch an activity if a cookie is in the page with mbox.js

  • November 30, 2017
  • 1 reply
  • 5304 views

Hi all,

I have a question about on how to target and launch an activity if the user has a cookie on his browser.

I already saw different solutions but apparently any on those seems to work to me, probably I'm missing something.

Could someone explain me step by step what it needs to be done?

Please be aware that this will need to work with mbox.js (so not at.js).


Thank you so much,
Renato

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

1 reply

YogitaBist
Level 3
December 1, 2017

Hi @renatob2547702 ,

You could also set cookie using profile script for the targeted page and then use it in audience..

you can find the code for setting cookie in help section if not use the below code :

if (mbox.name == "xy")

{

  // this will set cookie

  user.setLocal('product', 'zz');

  // this is how we read cookies in Test& Target

  var zz = user.getLocal('zz');

  // cookies exist

  if (zz)

  {

  return zz;

  }

}

and then pass the value in audience . user.cookie equals - product

In case you are looking for cookie from other source.. you could use [Not sure if this works i have not tried it, though you could give it a try]

if(document.cookie = "Cookie name") {

// your code

}

Hope this was helpful

December 1, 2017

Hi Yogita, thank you so much for your answer.


I suppose I have to paste the code you wrote inside a profile script.

Question now are:


Since I have only to read the cookie, I think I can remove the line:

// this will set cookie

  user.setLocal('product', 'zz');

Is this correct?


Also, what are exactly "product" and "zz"? It seems like I have to replace these.

Then, when creating the audience based on a visitor profile (so passing a value for the "equals" condition), which value should I pass, product or zz?
If "product", why on the 'read the cookie' code I pass only "zz"?

I know this could be a little bit much but let me know for any question or clarification.


Thank you again,

Renato

YogitaBist
Level 3
December 5, 2017

@@renatob25477023 

I am afraid i am not completely aware if you  could read the cookies locally stored in the "browser" with the help of profile script.

We will have to find that out.

You can also go with the second approach ..

you can simply add the condition in your campaign code.

if(document.cookie = "Cookie name") {

// your code

}

I would suggest you to try this approach. This will solve your problem without modifying the audience.