amitmerchant1990 / reverie

:art: A ridiculously elegant Jekyll theme.
https://reverie.pages.dev
MIT License
775 stars 676 forks source link

Add Google Analytics GA4 code (Issue #45) #48

Closed Kolossi closed 3 years ago

Kolossi commented 3 years ago

Hi Amit,

Thanks for all your work on this great theme.

I noticed Issue #45 about new style "GA4" analytics and I had already fixed it in my generated version, so here is a PR for you to review.

There's different ways to tackle this - maybe auto-detect by looking at the form of the google_analytics id given ("G-..." or "UA-...").

In my version I just used 2 config values. It also looks if GA4 is set and if so doesnt include the old UA stuff. Someone might want it though I guess, so I didn't do that in this PR.

(To do it, my analytics.html line 1: {% if site.google_analytics_ua and not site.google_analytics_ga4 %})

Note that as I'm starting fresh, in my site I also renamed the existing google_analytics to google_analytics_ua but that's very "breaky" for existing users!

Anyway, this PR as it is seems to me like a non-breaking easy implementation for the main repo.

YMMV, but my wish is that this at least saves you a little time in addressing the issue.

Thanks again for a great theme.

Paul

amitmerchant1990 commented 3 years ago

Thanks for the PR @Kolossi.

I would just suggest you move the logic to _includes/analytics.html file instead of creating a separate file. As I think, all the analytics code should live in a single file so it becomes more maintainable.

Thanks!

Kolossi commented 3 years ago

Thx.

I sure would have done, but the reason I didn't is one style needs to go in head, the other in body. Any ideas how to tackle that?