Can I get user based segments with API call rtp("get","visitor",)? | Community
Skip to main content
s_watanabe-1
Level 2
October 5, 2018
Question

Can I get user based segments with API call rtp("get","visitor",)?

  • October 5, 2018
  • 1 reply
  • 4917 views

Hi,

I'm trying to get visitor segments and show contents for segments not by RTP template.

I've got my own segments with API call like rtp('get','visitor',function(e){console.log(e.results)})

But it seems to be session based, After I reopen browser and call API, e.results returns nothing.

Did I misunderstand something? Is there any way to get cookie or user based segments with API call?

tested on

windows 10 64bit

Google Chrome 69.0.3497.100

1 reply

Yanir_Calisar2
Level 2
October 7, 2018

Hey

This is the expected behavior since a segment matches visitors only once per session (session lasts 30 minutes).

You'd have 2 option to achieve what you described:

1. When a visitor matches one of your relevant segments - store this in a new cookie you create and use it to personalize the pages for as long as you want.

2. Use the RTP's campaign editor as your code editor and "inject" the code of your custom campaign to the website when a visitor matches the segment.

You can also set the RTP campaign to be sticky and then it will show up during the whole session.

s_watanabe-1
Level 2
October 9, 2018

Hey

This is the expected behavior since a segment matches visitors only once per session (session lasts 30 minutes).

Thanks Yanir,

I didn't know that, and understood.

1. When a visitor matches one of your relevant segments - store this in a new cookie you create and use it to personalize the pages for as long as you want.

2. Use the RTP's campaign editor as your code editor and "inject" the code of your custom campaign to the website when a visitor matches the segment.

I think Option2 is easy for development. and I tried that.

I set DOM to my test page html.

<div id="inject_test"></div>

And  create campaign and INJECT my code to rtp zone html editor like    var my_campaign="inject_test";

It worked well, I can get my_campaign variant in javascript.

But After I reopen my browser, code injection doesn't work and my_campaign variant returns undefined.

I don't understand why does it happen. any Ideas for this?

Yanir_Calisar2
Level 2
October 10, 2018

Yes - you only need to enable the "sticky" option:

This will make the campaign keep showing up for the rest of the session.