Updated: Comment #3

Problem/Motivation

The following Javascript gets written to the page:

varf=d.getElementsByTagName(s)[0];
varj=d.createElement(s);
vardl=l!='dataLayer'?'&l='+l:'';

Note the "var" statement is not properly separated from the variable names it is trying to create. When the code later tries to run f.parentNode.insertBefore(j,f);, f is NULL and j isn't a full DOM Element object.

Proposed resolution

Don't remove single-spaces in the Javascript code.

Remaining tasks

Review, RTBC, Commit.

User interface changes

None.

API changes

None.

CommentFileSizeAuthor
#3 google_tag-2209835-3.patch449 bytesmparker17

Comments

mparker17’s picture

Priority: Critical » Major

Okay, actually, this only happens if the module is set to compact the output so I'm downgrading from Critical to Major.

mparker17’s picture

Issue summary: View changes
mparker17’s picture

Issue summary: View changes
StatusFileSize
new449 bytes

It turns out the linebreak in the middle of the iframe tag in the noscript section was causing HTML that looked like ns.html?id=GTM-00000"height="0" to be output, which should be fine but could in theory throw off some browsers.

Since the goal of the "compact" option is to remove as much unnecessary whitespace as possible, but keep the HTML and JS valid, I figured it would be best to preg_replace all instances of 1 or more pieces of whitespace with a single space. In practice, this causes a bit more whitespace than strictly necessary, but it's better than causing Google Tag Manager to stop working in browsers with JS enabled :)

If we really wanted to bikeshed, I couldn't find recent performance statistics for preg_replace versus str_replace but they were pretty close for simple replacements in early 2011.

solotandem’s picture

Assigned: mparker17 » solotandem
Status: Active » Fixed

Thanks for noting this. Obviously, it was not the intention to remove all spaces, but a simple oversight. To fix this, I retained the simple string replacement instead of switching to a regular expression routine.

Fixed in this commit.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.