Match method with Regex to fire tag on certain site pages

Avatar

Avatar
Boost 1
Level 1
mn6
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile

Avatar
Boost 1
Level 1
mn6
Level 1

Like

1 like

Total Posts

2 posts

Correct reply

0 solutions
Top badges earned
Boost 1
View profile
mn6
Level 1

04-12-2018

I'm trying to fire a Google GTAG script only on certain language variations of our site, I can't create a condition to fire this in our Tag Manager as it will impact other tags and pixels firing on the page rule.

I wan't the tag to fire only on certain language variations: '^/(at|cn|cz|de|dk|en|eu|fr|it|nl|no|pl|pt|pt-br|se)/)'

I'm trying to achieve this by using match method with Regex but I am getting a syntax error that I can't figure out on the below script: "Uncaught SyntaxError: Unexpected token ^" which I believe to be coming from the '^' at the start of regex string, however I need to only pull back pages that include the ISO market name (e.g. /en/) at the start of a URl string (e.g. /en/mypage/mysubpage)

if (location.pathname.match(^\/(at|cn|cz|de|dk|en|eu|fr|it|nl|no|pl|pt|pt-br|se)\/); {

{

  
var script = document.createElement('script');

  script
.setAttribute('src','https://www.googletagmanager.com/gtag/js?id=DC-XXXXXX');

  document
.head.appendChild(script);
  window
.dataLayer = window.dataLayer || [];
  
function gtag(){dataLayer.push(arguments);}
  gtag
('js', new Date());
  gtag
('config', 'DC-XXXXXXX');
}
 
}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
StewSchilling
MVP

Likes

342 likes

Total Posts

278 posts

Correct reply

85 solutions
Top badges earned
Coach
Give Back 25
Springboard
Bedrock
Validate 1
View profile

Avatar
Coach
MVP
StewSchilling
MVP

Likes

342 likes

Total Posts

278 posts

Correct reply

85 solutions
Top badges earned
Coach
Give Back 25
Springboard
Bedrock
Validate 1
View profile
StewSchilling
MVP

11-12-2018

should be

when using

the expectation is a regExp starting and ending with / .   For example :

Answers (0)