The Google Analytics Plugin for Grav CMS allows you to integrate and configure Google Analytics without the need to touch any code within your Grav site.
- Preload the Google Analytics script asynchronously
- IP Anonymization
- Choose the Google Analytics code position in the HTML document (head or body).
- Force SSL (HTTPS). Send all data using SSL, even from insecure (HTTP) pages.
- Renaming of the Global (ga) Object
- Debug Mode with Trace Debugging
- Custom Cookie Configuration. Name, domain and expiration time are configurable.
- Blocking IP Addresses
- Multi-Language Support for the Grav Administration Panel
Installing the Google Analytics plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's terminal (also called the command line). From the root of your Grav install type:
bin/gpm install ganalytics
This will install the Google Analytics plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/ganalytics.
To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to ganalytics. You can find these files on GitHub or via GetGrav.org.
You should now have all the plugin files under
/your/site/grav/user/plugins/ganalytics
NOTE: This plugin is a modular component for Grav which requires Grav to operate.
Before configuring this plugin, you should copy the user/plugins/ganalytics/ganalytics.yaml to user/config/plugins/ganalytics.yaml and only edit that copy.
Here is the default configuration and an explanation of available options:
enabled: true
trackingId: ""
position: "head"
objectName: "ga"
forceSsl: false
async: false
anonymizeIp: false
blockedIps: []
cookieConfig: false
cookieName: "_ga"
cookieDomain: ""
cookieExpires: 63072000
debugStatus: false
debugTrace: false-
enabledToggles if the Google Analytics plugin is turned on or off. -
trackingIdThe Google Analytics Tracking ID. This value is required. -
positionCode Position in the HTML document (headorbody). Default ishead. -
asyncToggles if the Google Analytics script is preloaded asynchronously. -
forceSslToggles if Google Analytics should send all data using HTTPS. -
objectNameThe name for the global (ga) object. Default isga. -
anonymizeIpToggles if Google Analytics will anonymize the IP address for all hits. -
blockedIpsHere you can blacklist IP addresses. For those the Google Analytics script will not be embedded. -
cookieConfig: Toggles if the a custom cookie configuration should be used. -
cookieNameThe cookie name. Default ist_ga -
cookieDomainThe cookie domain. -
cookieExpiresThe cookie expiration time in seconds. Google default is 2 years (63072000seconds) -
debugStatusToggles if the debug version of Google Analytics is enabled or disabled. -
debugTraceToggles if the debugger will output more verbose information to the console.debugStatusmust be enabled.
- 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.