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?

  • August 6, 2020
  • 15 replies
  • 67 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.

15 replies

Eric Fitz
Employee
Forum|alt.badge.img+5
  • Employee
  • August 7, 2020

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


  • Author
  • Connector
  • August 8, 2020

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
  • August 12, 2020

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
  • August 12, 2020

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
  • August 13, 2020

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
  • August 13, 2020

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
  • August 13, 2020

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
  • August 13, 2020

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
  • August 13, 2020

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


  • Author
  • Connector
  • August 17, 2020

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
  • August 19, 2020

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
  • September 30, 2020

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
  • September 30, 2020

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
  • September 30, 2020

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


  • Active User
  • November 10, 2020

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...