Using regex for url in triggers
AnsweredI wanted a trigger to work when the users were on two areas of our website. I tried to use a regex to do this. I tried a couple of versions. First a simple one (that works in Python):
portal.somniumtech.com/products|www.somniumtech.com
Then, because of the slightly cryptic comment about only doing a "full" match, I tried:
^https?://(portal.somniumtech.com/products|www.somniumtech.com).*$
In both cases, the trigger never fired.
I worked around this by using the (undocumented) developer mode and using nested conditionals:
"condition": [
"and",
[
"or",
[
"icontains",
"@visitor_page_url",
"portal.somniumtech.com/products"
],
[
"icontains",
"@visitor_page_url",
"www.somniumtech.com"
]
],
That seems to work. But means I can't switch back to the Visual view.
Any idea why the regex doesn't work?
-
After a lot of fiddling about trying to diagnose another problem, I found the following regex does work:
.*www.somniumtech.com.*|.*portal.somniumtech.com/products.*
I assume the regex engine is very limited in what it accepts. Apparently not Python regexes as implied by the documentation.
-
Hi Jamie,
The 2 regex examples you gave above should work. In order to ensure the integrity of our triggers, we actually do not fire events if a page refresh on the same page URL happens. This makes sures that triggers only fires on a true page load event.
Perhaps you can try these regexes again, and open your pages in incognito to see if the trigger really fires
-
Hi Yunen,
Thanks for the reply. I think you are right: I was probably using page refreshes to test the trigger. This would explain why I had such a hard time getting it to fire. I think I spent a lot of time trying to debug problems that weren't there!
Is this fact documented anywhere? How about a blog post with tips on how to test triggers...?
-
Hi Jamie,
Good idea on an article on how to test triggers. Let me speak to my content team and see if they can whip something up!
-
Hi,
I put a few of my ideas in the Tips & Tricks section:
Post is closed for comments.
5 Comments