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

Beacon parameter inconsistencies from their original GA4 specs #52

Open
hexalys opened this issue Sep 2, 2023 · 0 comments
Open

Beacon parameter inconsistencies from their original GA4 specs #52

hexalys opened this issue Sep 2, 2023 · 0 comments
Labels
ga4 help wanted Extra attention is needed needs verification Issue needs to be verified

Comments

@hexalys
Copy link

hexalys commented Sep 2, 2023

Context: Derived from the jsDeliver source of minimal-analytics, I created tag.js which has evolved into a more advanced self-hosted substitute with basic dataLayer functionality and most gtag() configuration fields, with roughly 90% web features, including all GA4 Enhanced Measurements, combined into a light 5.5k gzipped size (10KB minified original).

My goal is not to ask for changes, or to submit pull request; as I am not very savvy in Typescript anyway, and there are many fundamental flaws to address... This is a tweet follow-up, to try and point out the core issues I encountered along the way, working from the minimal-analytics js source. (For helpful reference, I posted tag.js as a private gist at the moment.)

Current GA4 mismatch or misconceptions:

  1. sessionStorage is not adequate as it's not multi-tab compatible (single window only). GA4 cookies provide full compatibility with multiple tabs or windows. localStorage only is better suited for all parameters that need storage.

  2. The fv firstVisit is a function of is_new_to_site not is_new_session.

  3. The _s hit count is the number of events sent during a page view session. Not just a static 1. e.g. A scroll event after page_view would qualify as _s=2

  4. The sid sessionId does not change until a new session starts. It's the last part of the permanent _ga cookie representing the sessionStart timestamp. @thyngster has a lot of helpful references on his Google Analytics 4 Measurement Protocol CheatSheet.

  5. The sct session count is accurately stored. However the way it works, is that it's only incremented on inactivity after a 30 minutes default from the sessionStart (sid) timestamp. See this tweet for additional context.

  6. seg sessionEngagement is complex. In brief, it starts with 0 and keeps switching, with 'conversion' event exceptions.

  7. The beforeunload event is not reliable. I opted with pagehide at the moment, alongpageshow for auto page_view(s).

  8. Unless I am missing something, you can much simplify that overkill scroll percentage function with the following:
    Math.round(100 * Math.abs(document.documentElement.scrollTop / (document.documentElement.scrollHeight - document.documentElement.clientHeight)))

  9. Per my tests and implementation, ep.search_term is not a parameter sent along other events (such as page_view), and only one event name at a time is supported. ep.search_term is either sent in the beacon payload as a batched parallel event, or a separate view_search_results event but not together by default, as it is now.

@jahilldev jahilldev added ga4 help wanted Extra attention is needed needs verification Issue needs to be verified labels Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ga4 help wanted Extra attention is needed needs verification Issue needs to be verified
Projects
None yet
Development

No branches or pull requests

2 participants