Closed szepeviktor closed 10 years ago
Interesting. Thanks @szepeviktor!
I use a WP global object (printed in the head by WordPress)
// AMD module: analytics
// https://gist.github.com/ismyrnow/6252718
define('analytics', function (require) {
var module;
// Setup temporary Google Analytics objects.
window.GoogleAnalyticsObject = 'ga';
window.ga = function () { (window.ga.q = window.ga.q || []).push(arguments); };
window.ga.l = 1 * new Date();
// Immediately add a pageview event to the queue.
window.ga('create', WP.ga.UA, WP.ga.domain);
window.ga('send', 'pageview');
// Create a function that wraps `window.ga`.
// This allows dependant modules to use `window.ga` without knowingly
// programming against a global object.
module = function () { window.ga.apply(this, arguments); };
// Asynchronously load Google Analytics, letting it take over our `window.ga`
// object after it loads. This allows us to add events to `window.ga` even
// before the library has fully loaded.
require(['ga']);
return module;
});
I couldn't find in google - so I've made an issue
this is a working (tested) AMD module for Google Analytics (Universal Analytics analytics.js) https://gist.github.com/ismyrnow/6252718