4 Replies Latest reply on Oct 15, 2018 4:33 PM by s watanabe

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

    s watanabe

      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

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

          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.

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

              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?

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

                  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.

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

                      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.