Skip to main content
The Grain plugin installs the Grain Tag, adds WordPress context to every page view, and tracks WooCommerce events. This page installs the plugin first. A second method adds the script by hand. The plugin method takes about 5 minutes.

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

  1. Download grain-tag-4.4.0.zip.
  2. In the WordPress admin, go to Plugins, then Add New.
  3. Click Upload Plugin at the top.
  4. Click Choose File and select the downloaded zip file.
  5. Click Install Now, then Activate.
The dashboard also offers the plugin. When you add a new site in the dashboard, select “WordPress”. The guided setup downloads the plugin for you.

2. Configure the plugin

  1. Go to Settings, then Grain Analytics.
  2. Enter your tenant alias.
  3. Make sure that tracking is enabled. It is on by default.
  4. If WooCommerce is installed, select the WooCommerce events to track.
  5. Click Save Settings.
The plugin works with optimization plugins such as WP Rocket and Autoptimize. The settings page also holds these options:

3. Test the plugin

  1. On the same settings page, click Send Test Event at the bottom.
  2. Open the dashboard and make sure that the test event is there.
  3. 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 global grainTrack 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.
Read Name events for the naming convention.

Form submissions

Each form plugin fires its own browser event. Add the snippet for your form plugin. Contact Form 7:
Gravity Forms:
WPForms:

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.
Do not edit the files of your parent theme. A theme update deletes the edit. Use a header and footer plugin, or a child theme.
  1. Install a plugin such as “Insert Headers and Footers” or “WP Code”.
  2. Go to Settings, then Insert Headers and Footers.
  3. In Scripts in Header, paste this code:
  1. Replace your-tenant-id with your tenant alias.
  2. Click Save.

Option B: child theme

Add this code to the functions.php file of your child theme:

Test the script

  1. Open your site in a private (incognito) window.
  2. Open the browser console (F12, then Console).
  3. Type window.GrainTag. The console shows the GrainTag object.
  4. Open a few pages, then open the dashboard and make sure that the page views are there.
With this method, send a custom event with 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.