Web Personalization (RTP) dynamically updating text | Community
Skip to main content
Aaron_Krug
Level 2
January 10, 2018
Question

Web Personalization (RTP) dynamically updating text

  • January 10, 2018
  • 1 reply
  • 2884 views

Is there a way in RTP to dynamically update the text in a web campaign with the name of the state that the visitor is currently in? I know I could create 50 different segments and campaigns for each state but was hoping not to have to do that.

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

1 reply

January 11, 2018

See: User Context API

You can use rtp.userContext.location.state to retrieve the state name and then develop a javascript that adds it into your campaign text/link.

<div id="state-name">Your State</div>

<script>

$('#state-name').text(rtp.userContext.location.state);

</script>

Aaron_Krug
Level 2
January 12, 2018

Thanks for the response but I am not able to get it to work. In the console I am just getting

Uncaught TypeError: Cannot read property 'location' of undefined.

I have also had User Context API enabled for my account.

Am I missing something?

Yanir_Calisar2
Level 2
February 10, 2018

Could you send me a link to your website? I'll take a look.

Basically you need to wrap this script with some function that waits for the rtp.userContext object to be ready and only then replace the content.

Also, it's recommended to validate that  rtp.userContext.location.state is not undefined (rtp.userContext.location.state != undefined).

This to avoid an error when people are visiting from countries that don't have states.