Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var lineRegex = /(<%= settings\.load %>|<%= settings\.page %>|}}\(\);)/g;
var versionRegex = /<%= settings\.version %>/;
var snippet = template(source.replace(optionalCDNRegex, '$1').replace(loadRegex, '$1').replace(pageRegex, '$1').replace(versionRegex, packageJSON.version), { variable: 'settings' });
var snippetMin = template(minify(source, {
mangle: { except: ['analytics', 'key'] },
compress: { sequences: false, side_effects: false },
mangle: { except: ['analytics', 'key', 't', 'e'] },
compress: { sequences: false, side_effects: false, },
fromString: true
}).code.replace(optionalCDNRegex, '$1').replace(loadRegex, '$1').replace(pageRegex, '$1').replace(lineRegex, '\n$1').replace(versionRegex, packageJSON.version), { variable: 'settings' });

Expand Down
17 changes: 9 additions & 8 deletions template/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@
// for methods in Analytics.js so that you never have to wait
// for it to load to actually record data. The `method` is
// stored as the first argument, so we can replay the data.
analytics.factory = function(method){
analytics.factory = function(e){
return function(){
if (window.analytics.initialized) {
// Sometimes users assigned analytics to a variable before analytics is done loading, resulting in a stale reference.
// If so, proxy any calls to the 'real' analytics instance.
return window.analytics[method].apply(window.analytics, arguments);
return window.analytics[e].apply(window.analytics, arguments);
}
var args = Array.prototype.slice.call(arguments);
args.unshift(method);
args.unshift(e);
analytics.push(args);
return analytics;
};
};


// For each of our methods, generate a queueing stub.
for (var i = 0; i < analytics.methods.length; i++) {
var key = analytics.methods[i];
Expand All @@ -70,14 +71,14 @@
// and that will be sure to only ever load it once.
analytics.load = function(key, options){
// Create an async script element based on your key.
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = "https://<%= settings.host %><%= settings.ajsPath %>";
var t = document.createElement('script');
t.type = 'text/javascript';
t.async = true;
t.src = "https://<%= settings.host %><%= settings.ajsPath %>";

// Insert our script next to the first script element.
var first = document.getElementsByTagName('script')[0];
first.parentNode.insertBefore(script, first);
first.parentNode.insertBefore(t, first);
analytics._loadOptions = options;
};
analytics._writeKey = '<%= settings.apiKey %>';
Expand Down