Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 15, 2024

Conversation

kzar
Copy link
Contributor

@kzar kzar commented Feb 15, 2024

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

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
Copy link
Collaborator

@dharb dharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you @kzar

@dharb dharb merged commit 57b338a into duckduckgo:main Feb 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants