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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic GA4 support #330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

basic GA4 support #330

wants to merge 1 commit into from

Conversation

tgaff
Copy link

@tgaff tgaff commented Sep 11, 2023

The old Universal Analytics support ended on July 1st, 2023. This migrates to GA4.

This may resolve #310

I believe this code is working - at least for the non-PRO case. I can't test PRO (e.g. cookie banner) since I don't have access. So I've tried to interpret the old code and I hope get close to what was happening there. That being said, I'd really suggest testing and likely improving this before merge. I don't have deep knowledge on Hydejack, GA or even Jekyll. 馃し This just seems to work for my use-case.

There are some major GA4 changes. Initialization is different, consent is different and binding to browser history API is automatic if enabled in the GA control panel (default is on).

I'll be doing further testing of this in the coming week, but wanted to post this as a starting point.


useful:

comparison of GA with GTAG function calls
https://developers.google.com/tag-platform/security/guides/consent
https://developers.google.com/analytics/devguides/collection/ga4/reference/config

Comment on lines -24 to -32
var pushStateEl = d.getElementById('_pushState');
var timeoutId;
pushStateEl.addEventListener('hy-push-state-load', function() {
w.clearTimeout(timeoutId);
timeoutId = w.setTimeout(function() {
ga('set', 'page', w.location.pathname);
ga('send', 'pageview');
}, 500);
});
Copy link
Author

Choose a reason for hiding this comment

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

GA4 watches the pushState API on it's own so I believe this is no longer needed. However I believe the feature has to be enabled as part of "Enhanced Metrics" in order to work. At least on my account it appeared to be enabled by default.
It may be worth documenting this.
Screen Shot 2023-09-11 at 1 35 53 PM

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.

Current Google Analytics support will cease to work next year.
1 participant