Can I use regexp to hide operator on the product page? | Community
Skip to main content
Answered

Can I use regexp to hide operator on the product page?

  • Aug 6, 2020 7:38 AM UTC
  • 15 replies
  • 179 views

For example, I have this URL pattern in my node app — /:lang/:citySlug-d:cityId([0-9]+)/:productSlug-p:productId([0-9]+)/

Example — https://mywebsite.com/en/barcelona-d1/el-born--picasso-museum-p19//p>

 

How do I hide operator on pages, which follow this pattern?

Best answer by Kirill C

Hey @eric f11​, I found a way to do the desired behavior. I use Google Tag Manager to install Intercom on my website, so I just created a new tag with JS code hiding Launcher with trigger on specific pages. It worked great.

 

Side note: to convert paths I had, I use node lib 'path-to-regexp', e.g. path `/:lang/:citySlug-d:cityId([0-9]+)/:productSlug-p:productId([0-9]+)/` become `^\/(?:([^\/]+?))\/(?:([^\/]+?))-d(?:([0-9]+))\/(?:([^\/]+?))-p(?:([0-9]+))\/?$`.

 

Screenshots of my set up:

 

I hope it will help someone.

View original

15 replies

Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 7, 2020 11:10 AM UTC

Hey @kirill c​! Do you mean Operator's task bots, or a Custom Bot?


  • Author
  • Connector
  • Aug 8, 2020 6:08 AM UTC

Hey! I mean the settings to control inbound communications, so I need to hide Intercom button on some pages as described


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 12, 2020 1:03 PM UTC

Got you! I'm afraid my regex reading skills are pretty poor 🙈 which would be the variables in that URL? Looks like the language, city and product?


  • Author
  • Connector
  • Aug 12, 2020 1:30 PM UTC

Yes, you are right. No worries, I am also noob in regexp, however see this example in online regexp tool — https://regex101.com/r/biZs5t/1/p>

 


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 13, 2020 9:30 AM UTC

Gotcha, thank you! I've checked with our team and I'm afraid we don't support regex in the Messenger visibility settings. However, that doesn't mean that you can't do what you want to do! How many possible language variations are there in the URL? (e.g. /en/, /fr/ etc.)


  • Author
  • Connector
  • Aug 13, 2020 9:40 AM UTC

Intriguingly. How? For now, I have two language versions, but product slug could contain any a-z character


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 13, 2020 9:43 AM UTC

What I'm thinking here is using the options:

 

Page URL starts with https://mywebsite.com/en//b>

OR

Page URL starts with https://mywebsite.com/fr//b>

 

Or am I naively thinking that the only slugs that will follow language are the product and city ones?


  • Author
  • Connector
  • Aug 13, 2020 9:54 AM UTC

I can give you more context. Here is a few examples of

  • Cities (Intercom Icon Button needed)

https://example.com/en/paris-d3/

https://example.com/en/barcelona-d1/

 

  • Products (Intercom Icon Button is not needed)

https://example.com/en/barcelona-d1/the-basilica-of-the-sagrada-familia-p13/

https://example.com/en/paris-d3/la-sainte-chapelle-p58/

 

What conditions come to your mind to make it work?

 


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 13, 2020 10:01 AM UTC

In the "Cities" slug, how many possible variations of d1, d3 are there?


  • Author
  • Connector
  • Aug 17, 2020 9:13 PM UTC

Hey Eric! It could be thousands of them. We launched a website, you can check it out here: https://wegotrip.com/p>


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Aug 19, 2020 9:50 AM UTC

Thanks for clarifying that for me! I'm starting to think that the best solution available to you here is a programatic one.

 

You can include a hide_default_launcher: parameter in your Messenger script. My recommendation would be to set up a script, using your regex, that changes the value of this parameter from false to true (a true value hides the launcher). What do you think?


  • Author
  • Connector
  • Answer
  • Sep 30, 2020 10:06 AM UTC

Hey @eric f11​, I found a way to do the desired behavior. I use Google Tag Manager to install Intercom on my website, so I just created a new tag with JS code hiding Launcher with trigger on specific pages. It worked great.

 

Side note: to convert paths I had, I use node lib 'path-to-regexp', e.g. path `/:lang/:citySlug-d:cityId([0-9]+)/:productSlug-p:productId([0-9]+)/` become `^\/(?:([^\/]+?))\/(?:([^\/]+?))-d(?:([0-9]+))\/(?:([^\/]+?))-p(?:([0-9]+))\/?$`.

 

Screenshots of my set up:

 

I hope it will help someone.


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Sep 30, 2020 10:08 AM UTC

That's amazing, @kirill c​! Delighted that you found a workaround - how long do you have this in production? Have you encountered any unexpected behaviour?


Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • Sep 30, 2020 10:09 AM UTC

This would also be a great one for our @Tips, Tricks, and Workarounds​ group!


  • Active User
  • Nov 10, 2020 3:57 PM UTC

We also use GTM to deploy the code snippet and you have lots of creative ways to fire or not fire the code based on page, time of day, day of week, etc...