Using javascript expression in targeting criteria - to target based on text found on page | XM Community
Solved

Using javascript expression in targeting criteria - to target based on text found on page

  • 13 July 2022
  • 6 replies
  • 224 views

Userlevel 1
Badge +2

Hi,
I have an intercept that I am wanting to trigger on exit intent, however not after the customer has successfully submitted a website form. The challenge is that the URL does not change after the form is submitted.
I have tried to limit the pop-up from triggering to only when certain text is visible on page, however this doesn't seem to be working correctly.
The Javascript expression I was entering in the targeting criteria is below
document.body.textContent.includes("First name")
With the criteria of the above expression equal to True.
Can anyone point out where I might be going wrong? Thank you!

icon

Best answer by AmaraW 19 July 2022, 00:22

View original

6 replies

Userlevel 4
Badge +18

AussieQualtricsUser - your code should work correctly if you are evaluating the javascript expression is equal to 'true' instead of 'True'. Can you confirm if that is not the issue here?

Badge +48

Hey there! One of our product managers contacted me, thinking you may be running into an issue because the text isn't seen on the page when the Qualtrics code is loaded. According to the product manager, we load our code snippet on page refresh. So, if items are changing after that point, we won't catch them. They provided a couple of options for you to consider: 

  1. Our new Google Data Layer targeting looks for events happening in real-time, and will re-evaluate the code snippet once something has changed on the website. If these points are connected through Google Tag Manager, then this would be the easiest connection. Check out this Support Page > 

  2. API calls can be used to simulate a page refresh on their own once certain events happen on the page, like entering text into a field, etc. Check out this Support Page > 

Userlevel 1
Badge +2

Thank you Mishraji - this solved the Javascript expression. So simple, but I'm a Javascript dummy here haha. Appreciate your input.

Userlevel 1
Badge +2

Thanks very much AmaraW - yes you're exactly right. The single page application has been giving us headaches getting our use case to work. The input you've provided is really helpful, and gives us some options to explore.
Thanks all the for assistance.

Badge +48

https://community.qualtrics.com/XMcommunity/discussion/comment/47823#Comment_47823So glad we were able to help! 😃

Badge

As far as I can tell, the documentation does not specify this so I could be wrong. It looks like the JavaScript condition you input is going to be evaluated as a string. If you’re returning a true or false value (or anything else that isn’t a string) you’ll need to convert it to a string in the expression.

Leave a Reply