duckduckgo / tracker-surrogates

💉 Surrogates are small scripts that our apps and extensions serve in place of trackers that cause site breakage when blocked.
Other
20 stars 11 forks source link

Improve the analytics.js shim to handle more ways of using the ga API #40

Closed kzar closed 7 months ago

kzar commented 7 months ago

It turns out that a website can do something like

ga(tracker => { ... });

and the inline function should be called. That wasn't handled yet, so let's add the necessary logic from Mozilla's shim script[1] (but adjusted as necessary).

It also turns out that websites sometimes have their own inline definition of ga(), that assigns any call arguments to the ga.q queue. The calls in the queue are supposed to be made with the real ga() function, once that has been loaded. This also wasn't handled yet in our shim.

I notice that we still do not handle further ways of using the ga API, in the future it might be worth just switching to Mozilla's script entirely.

1 - https://searchfox.org/mozilla-central/source/browser/extensions/webcompat/shims/google-analytics-and-tag-manager.js