Google Analytics (gtag.js) Plugin
The Google Analytics Plugin is an extension for Grav CMS. You can easily integrate and configure Google Analytics in your Grav CMS site using the global site tag (gtag.js) framework and API without the need to touch any code.
Important: This plugin uses the global site tag (gtag.js) framework and API for sending data to Google Analytics. If you prefer the deprecated Universal Analytics (analytics.js) library, please install the Grav Google Analytics Plugin of John Linhart and me.
- Easily integrate and configure Google Analytics (gtag.js) in your Grav CMS site
- Disable Google Analytics for different IP addresses
- Rename the global gtag() object
- Disable Analytics for opted-out users
- Disable advertising features
- IP anonymization
- Configure cookie settings
- Do Not Track (DNT) support
- Supported Languages:
Installing the Google Analytics plugin can be done in one of three ways: The GPM (Grav Package Manager) installation method lets you quickly install the plugin with a simple terminal command, the manual method lets you do so via a zip file, and the admin method lets you do so via the Admin Plugin.
GPM Installation (Preferred)
To install the plugin via the GPM, through your system's terminal (also called the command line), navigate to the root of your Grav-installation, and enter:
bin/gpm install grav-plugin-google-analytics
This will install the Google Analytics plugin into your
/user/plugins-directory within Grav. Its files can be found under
To install the plugin manually, download the zip-version of this repository and unzip it under
/your/site/grav/user/plugins. Then rename the folder to
Google Analytics. You can find these files on GitHub or via GetGrav.org.
You should now have all the plugin files under
Note: This plugin is a modular component for Grav which may require other plugins to operate, please see its blueprints.yaml-file on GitHub.
If you use the Admin Plugin, you can install the plugin directly by browsing the
Plugins-menu and clicking on the
Before configuring this plugin, you should copy the
user/config/plugins/google-analytics.yaml and only edit that copy.
Here is the default configuration and an explanation of available options:
enabled: true tracking_id: "" advertising_features: true anonymize_ip: false cookie_domain: "" cookie_expires: ~ cookie_prefix: "" cookie_update: true blocked_ips:  do_not_track: false object_name: "" opt_out: false
||Toggles if the Google Analytics plugin is turned on or off|
||Google Analytics Tracking ID like
||Disable the advertising features, when they are enabled in the GA admin area|
||Anonymize the IP addresses of hits sent to Google Analytics|
||For the given IP addresses the GA code will not be embedded|
||Override the automatic cookie domain configuration|
||Cookie expiration time in seconds. Default is 28 days|
||To avoid name conflicts you can change the prefix of the cookie|
||When set to false, cookies are not updated on each page load|
||To avoid name conflicts the global gtag() object can be renamed|
||Disable Google Analytics without removing the gtag.js tag|
Note: If you use the Admin Plugin, a file with your configuration named
google-analytics.yamlwill be saved in the
user/config/plugins/-folder once the configuration is saved in the Admin.
- Sign in to your Google Analytics account.
- Select the Admin tab.
- Select an account from the dropdown in the Account column.
- Select a property from the dropdown in the Property column.
- Under Property, click Tracking Info > Tracking Code.
- Copy the Tracking ID (a string like UA-000000-01)
- Add it to the configuration of this plugin.
The Google Analytics Plugin follows the GitFlow branching model, from development to release. The
master branch always reflects a production-ready state while the latest development is taking place in the
Each time you want to work on a fix or a new feature, create a new branch based on the
git checkout -b BRANCH_NAME develop. Only pull requests to the
develop branch will be merged.