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

s_watanabe
Level 2

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

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

6 REPLIES 6
Yanir_Calisar2
Level 3

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

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
Level 2

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

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

inject_test.JPG

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 3

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

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

Screen Shot 2018-10-10 at 12.37.48.png

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

s_watanabe
Level 2

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

Thank you Yanir!

Sorry, I overlooked sticky Option.

Actually you mentioned about sticky option on your first message.

But even after I toggled sticky option, I can't hold campaign status over sessions.

Next I tried to use user context API

http://developers.marketo.com/javascript-api/web-personalization/user-context/

Because API specification says,

"User Context JavaScript API exposes user and visitor level data across multiple sessions"

I created 3pages for test.

1. send data event page.

var customData = {value: 'test_dataEvent_1001'};

rtp('send', 'event', customData);

2. send user context API page.

rtp('set', 'customVar1', 'test_userContext_1002');

3. only marketo RTP tag page

Send nothing

but check visitor segment with html code for injection

<div id="INJECT_TEST_1"></div>

<div id="INJECT_TEST_2"></div>

Then, I visited page1 and 2, completed segment conditions. and close my browser, after 1hour, I visit page3

Injection worked as attatched image.

campaign_injection_test.PNG

It seems only user context API segments last across sessions.

I think Im going to use user context API for my website.

But I still confused why general segment conditions of URL filter or data event can't last across sessions, even with sticky options.

Is that an expected behavior? I'd like to learn more detailed specification.

Luke_Wotton
Level 4

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

wait wait wait - this needs to me much clearer when you're looking at a campaign as to what 'sticky' means

s_watanabe
Level 2

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

Ahhhhh sorry for my super late reply. and thank you for your comment!

I think I'm misunderstanding what sticky option...?

https://nation.marketo.com/docs/DOC-3509-web-personalization-rtp-faq-segments-and-campaigns

says,

"If the campaign is not Sticky, the visitor will only be shown the campaign once during their session, whether that be campaign A or B. In their next session, they will again only be shown the campaign once, and again it could be either campaign A or B."

It's not a matter how many times the user see the campaign...

I want to get the flags "the visitor mathces the segement or not" after nth(many) times of visit of user.