Before you start
You need three things:- Admin access to WordPress.
- Your tenant alias from the dashboard. It is the alias shown at the top of the dashboard, not the UUID.
- 5 minutes.
1. Install the plugin
- Download grain-tag-4.4.0.zip.
- In the WordPress admin, go to Plugins, then Add New.
- Click Upload Plugin at the top.
- Click Choose File and select the downloaded zip file.
- Click Install Now, then Activate.
2. Configure the plugin
- Go to Settings, then Grain Analytics.
- Enter your tenant alias.
- Make sure that tracking is enabled. It is on by default.
- If WooCommerce is installed, select the WooCommerce events to track.
- Click Save Settings.
3. Test the plugin
- On the same settings page, click Send Test Event at the bottom.
- Open the dashboard and make sure that the test event is there.
- Open a few pages of your site. The dashboard shows the page views as they arrive.
What the plugin tracks
The plugin sends these events without more configuration:
The Grain Tag itself also records clicks, scroll depth, and heatmaps. Read
Automatic tracking.
WooCommerce
The plugin detects WooCommerce and tracks these events without more configuration:
To send a WooCommerce event that the plugin does not track, add code to the
functions.php file
of your child theme. This example sends an event when a visitor adds a product to a wishlist:
Track custom events
The plugin defines a globalgrainTrack function. The first argument is the event name, the
second holds the properties, and the third can hold { flush: true }. Use flush for an event
that must leave the browser before the page changes, for example a form that redirects.
Form submissions
Each form plugin fires its own browser event. Add the snippet for your form plugin. Contact Form 7:Install the script by hand
Use this method when you cannot install the plugin. It installs the Grain Tag only. WordPress context and WooCommerce events are not added.Option A: header and footer plugin
- Install a plugin such as “Insert Headers and Footers” or “WP Code”.
- Go to Settings, then Insert Headers and Footers.
- In Scripts in Header, paste this code:
- Replace
your-tenant-idwith your tenant alias. - Click Save.
Option B: child theme
Add this code to thefunctions.php file of your child theme:
Test the script
- Open your site in a private (incognito) window.
- Open the browser console (F12, then Console).
- Type
window.GrainTag. The console shows theGrainTagobject. - Open a few pages, then open the dashboard and make sure that the page views are there.
GrainTag.track(eventName, properties) instead of
grainTrack. Read Track an event.
Troubleshooting
Read Troubleshooting for cases that are not specific to WordPress.
Next steps
Trackers
Track clicks on specific elements from the dashboard, without code.
Heatmaps
See where visitors click and how far they scroll.
Tracks
Build funnels and paths through your content.
Privacy and consent
What Grain stores, cookieless mode, and consent modes.