-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2488 from brave/inject-ubo-google-analytics-code
add google analytics polyfill, fixes brave/brave-browser#4402
- Loading branch information
Showing
6 changed files
with
144 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(function() { | ||
// https://developers.google.com/analytics/devguides/collection/analyticsjs/ | ||
var noopfn = function() { | ||
; | ||
}; | ||
var noopnullfn = function() { | ||
return null; | ||
}; | ||
// | ||
var Tracker = function() { | ||
; | ||
}; | ||
var p = Tracker.prototype; | ||
p.get = noopfn; | ||
p.set = noopfn; | ||
p.send = noopfn; | ||
// | ||
var w = window, | ||
gaName = w.GoogleAnalyticsObject || 'ga'; | ||
var ga = function() { | ||
var len = arguments.length; | ||
if ( len === 0 ) { | ||
return; | ||
} | ||
var f = arguments[len-1]; | ||
if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) { | ||
return; | ||
} | ||
try { | ||
f.hitCallback(); | ||
} catch (ex) { | ||
} | ||
}; | ||
ga.create = function() { | ||
return new Tracker(); | ||
}; | ||
ga.getByName = noopnullfn; | ||
ga.getAll = function() { | ||
return []; | ||
}; | ||
ga.remove = noopfn; | ||
// https://github.com/uBlockOrigin/uAssets/issues/2107 | ||
ga.loaded = true; | ||
w[gaName] = ga; | ||
// https://github.com/gorhill/uBlock/issues/3075 | ||
var dl = w.dataLayer; | ||
if ( dl instanceof Object && dl.hide instanceof Object && typeof dl.hide.end === 'function' ) { | ||
dl.hide.end(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters