Skip to content
● Critical PHP security fixes are out: update PHP on your Grav sites. What to do →

Where to install Google GA4 tag

Started by Stephan Burckhardt 3 years ago · 3 replies · 1180 views
3 years ago

Where do I install the GA4 header tag (on each page), since there does not seem to be a "header" tag in GRAV?

3 years ago

@stephanckdt, Template partials/base.html.twig is used by Quark as the base template for all inheriting templates like default.html.twig, blog.html.twig, etc.

I presume other themes follow the same logic.

If you inject the GA4 script in template partials/base.html.twig directly below the <head> element, all pages will contain the GA4 script.

3 years ago

@pamtbaau:
partials/base.html.twig

Thanks a lot, Pam. I'm non-techie. So where is the partials/base.html.twig on my GRAV backend to be found so I can insert the code? I'd appreciate step-by step.

3 years ago

@stephanckdt, In most themes, if not all, template base.html.twig can be found in folder /user/themes/yourtheme/templates/partials.

Be aware when updating a theme which you have downloaded, that you may loose your changes when a new version of the theme gets released. To prevent the loss of your changes, you should first create a child theme that inherits from your downloaded theme and make changes only in the newly created child theme. See Inheriting using the CLI.

Alternatively, you could use a plugin that loads the Analytics script, but unfortunately, none supports GA4 at the moment.

last edited 05/16/23 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 12 months ago
6 1284 12 months ago
Content & Markdown · by Ton Haarmans, 2 years ago
10 1015 1 year ago
Content & Markdown · by Jan L'Am, 2 years ago
4 888 2 years ago
Content & Markdown · by Leonardo, 2 years ago
3 813 2 years ago
Content & Markdown · by belthasar, 2 years ago
4 1232 2 years ago