Google Tag Manager code contains "unexpected token"

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
dicentra
Jr. Propeller Head
Posts: 4
Joined: Mon Mar 12, 2018 5:56 pm

Google Tag Manager code contains "unexpected token"

Post by dicentra »

I pasted this into the head of a master page:

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js ... efore(j,f);
})(window,document,'script','dataLayer','GTM-xxxxxxx');</script>
<!-- End Google Tag Manager -->

Flare says there's an unexpected = token (red =), that it was expecting a semicolon. So I add the semicolon and another error is displayed. I can't debug script, so I was wondering if anyone else knows how to deal with this.

Thanks!
RamonS
Senior Propellus Maximus
Posts: 4293
Joined: Thu Feb 02, 2006 9:29 am
Location: The Electric City

Re: Google Tag Manager code contains "unexpected token"

Post by RamonS »

Where did you put the semicolon? Just because one is claimed to be missing does not mean it needs to go right after the equal sign.
Where does that script come from? Did it ever work before?

Edit: Nevermind...I saw where you got that code from. When I try validating it in various tools they all flag an error.
I suggest you ask on forums that are targeted to Google Tag Manager. It does not seem to be an issue caused by Flare.
Seems to be a common issue based on this search
https://duckduckgo.com/?q=google+tag+ma ... moon&ia=qa
asbahr+
Propeller Head
Posts: 18
Joined: Tue Sep 29, 2015 4:54 am

Re: Google Tag Manager code contains "unexpected token"

Post by asbahr+ »

After much research, I found an answer that worked for me in the MadCap forums. There is an ampersand & character in the Google Tags script that the XML parser in Flare does not like. You have to escape it out. Refer to this entry on the forum.

viewtopic.php?f=13&t=30902&p=134073&hil ... en#p134073

Replace the & with &
Post Reply