ember-cli-google-analytics
ember-cli-google-analytics copied to clipboard
Runtime error with Ember CLI 0.2.5
Should this plugin work with Ember CLI 0.2.5? I added it to my project as described in the readme but I get this error when visiting the page:
Uncaught TypeError: window[globalVariable] is not a function(anonymous function) @ google-pageview.js:18
This is the line(s) which fail: https://github.com/pgrippi/ember-cli-google-analytics/blob/master/app/mixins/google-pageview.js#L16-L18
Used the latest 1.4.0. Is this a known issue?
Also get this error but on line 21. How did you fix this? For me only in combination with cordova the problem appears.
thx
I fear I don't remember the details, its too long ago. We updated in the meantime to a newer Ember CLI version and the problem vanished.
Do you still use Ember CLI 0.2.5?
I use 1.13.13. On normal browser all is fine so I guess in my case it might not be a problem with ember at all. I also build a cordova app and on android it breaks. I just hopped that you had a similar problem. :(
We're on Ember 2.14.1, have just installed ember-cli-google-analytics ^1.5.0 as per the installation instructions, and are seeing the same error. We're not using Cordova, it's just a plain Ember app running from the command line and accessed at localhost:4200
.
The error only seems to get thrown when I forcibly refresh the page. Navigating around our app without refreshing doesn't throw any errors, and seems to track as expected.
The line in question (see full stack trace below) is trying to perform the send (window[globalVariable]('send', 'pageview', {
), but my guess is that window.ga
isn't available at that point (which would explain why it only throws the error on a page refresh and not when navigating around).
Interestingly enough, when the error gets thrown, the tracking data still seems to get sent to our GA dashboard.
There was an error running your app in fastboot. More info about the error:
TypeError: window[globalVariable] is not a function
at Class.pageviewToGA (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/ew/mixins/google-pageview.js:22:1)
at Object.applyStr (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:45470:1)
at sendEvent (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:22871:1)
at Class.trigger (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:38519:1)
at invokeWithOnError (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:9035:1)
at Queue.flush (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:8923:1)
at DeferredActionQueues.flush (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:9086:1)
at Backburner.end (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:9165:1)
at Timeout.Backburner._boundAutorunEnd [as _onTimeout] (/sitepath/tmp/broccoli_merge_trees-output_path-0o3SJA8u.tmp/assets/vendor/ember/ember.debug.js:9134:1)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
Update:
Our error was probably down to window
not being available with FastBoot, so we edited our router.js
file to detect window.ga
and conditionally mix in the GA code:
import Ember from 'ember';
import config from './config/environment';
import OtherMixin from 'other-mixin';
import googlePageview from './mixins/google-pageview';
let routerData = {
location: config.locationType,
rootURL: config.rootURL
};
let Router;
if ('ga' in window) {
// Only add GA tracking if it's available (e.g. we're not using FastBoot)
Router = Ember.Router.extend(OtherMixin, googlePageview, routerData);
} else {
Router = Ember.Router.extend(OtherMixin, routerData);
}
Router.map(function() {
// ...
});
export default Router;
@BillyRayPreachersSon Thanks :) had the same issue..