Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Grav+GAnalytics

Solved by pamtbaau View solution

Started by Dmitry 5 years ago · 2 replies · 636 views
5 years ago

Hello. Could someone explain HOW TO connect GAnalytics in simpliest way?
No luck with plugins.
Telegram @emptty0

5 years ago

Just insert google code into HEADER section in this file
/user/themes/THEME/templates/partials/base.html.twig

👍 1
5 years ago Solution

@emptty0, That is indeed the most simple way.

To add a bit more flexibility you might consider adding test and production GA ID's in different config files, eg. /user/config/ganalytics.yaml containing the test Id and /user/env/mydomain.com/config/ganalytics.yaml containing the production Id.

HTML
// /user/config/ganalytics.yaml  -> Contains default setting
script: '<script>script with test key</script>'

// /user/env/mydomain.com/config/ganalytics.yaml
script: '<script>script with production key</script>'

And in /user/themes/your-theme/templates/partials/base.html.twig:

TWIG
{{ config.ganalytics.script | raw }}

Grav will automatically switch between config files depending on the domain.

👍 2

Suggested topics

Topic Participants Replies Views Activity
Plugins · by complanar, 2 weeks ago
2 252 4 days ago
Plugins · by Vladimir Novak, 1 month ago
3 594 1 month ago
Plugins · by Mathieu Lecouturier, 2 months ago
3 417 2 months ago
Plugins · by Slebeig, 2 months ago
1 530 2 months ago
Plugins · by Rene, 3 months ago
2 731 3 months ago