minified construct js can conflict with Google Analytics

Discussion and feedback on Construct 2

Post » Mon May 09, 2016 8:36 pm

I've been having a problem where mysteriously, Google Analytics wouldn't work with my game, but only when it was minified. As it turns out, with this particular game, my minified c2runtime.js includes a global variable named "ga". Unfortunately, Google Analytics uses "ga", so then i end up with conflicts and analytics stops working. When I run the exported game with the GA debugging extension, it tells me there's already an object named "ga" so errors may occur.

This seems mostly hopeless, but is there any way to control what globals are used when the code is minified? And I realize I'm an edge case, but it would be nice if in the future construct could avoid colliding with popular code libraries when minifying.
Posts: 6
Reputation: 183

Post » Mon May 09, 2016 8:51 pm

I should also add so if it helps anyone, I was able to get it working by replacing all instances of "ga" in the minified c2runtime with another variable (I used "xx"). With Sublime Text, replacing with the regex ga(?![a-z]) case insensitive did the trick.
Posts: 6
Reputation: 183

Post » Tue May 10, 2016 12:29 am

Good workaround. You might post that to the Bug forum. However I don't know if Ashley has direct control over the minifier's name choices,
Posts: 907
Reputation: 41,611

Post » Tue May 10, 2016 1:45 am

That's very interesting to know.
This is a predictable error that may often happen.
Two letter variable names are things from the past.
The minifier predicts correctly that noone else in the world is using those.
Posts: 111
Reputation: 3,994

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 3 guests