What You’ll Need
- Admin access to WordPress
- Your Grain tenant ID from grainql.com/dashboard
- 5 minutes
Method 1: Official Plugin (Recommended)
The easiest and most powerful method—automatic tracking for WordPress and WooCommerce.Features
- ✅ Automatic page view tracking with rich WordPress context (post type, categories, tags, author)
- ✅ WooCommerce e-commerce tracking - product views, add to cart, checkout, purchases
- ✅ Zero configuration - just add your Tenant ID and start tracking
- ✅ Privacy-first - GDPR-compliant cookieless tracking
- ✅ Optimization plugin compatible - works with WP Rocket, Autoptimize, and others
- ✅ Lightweight - minimal performance impact
Download and Install
Option A: Direct Download- Download the plugin: grain-analytics-4.0.2.zip
- Go to Plugins → Add New in WordPress admin
- Click Upload Plugin at the top
- Click Choose File and select the downloaded zip file
- Click Install Now → Activate
Configure the Plugin
- Go to Settings → Grain Analytics in your WordPress admin
- Enter your Tenant ID from grainql.com/dashboard
- Enable tracking (on by default)
- Choose which WooCommerce events to track (if WooCommerce is installed)
- Click Save Settings
- Use the Send Test Event button to verify integration
What Gets Tracked Automatically
WordPress Events:- Page views with context (post type, categories, tags, author)
- Blog post engagement
- Search queries
- Comment submissions
- User registration/login
- Product views with full details
- Add to cart / Remove from cart
- Cart views
- Checkout started
- Order completed
- Coupon applied/removed
Method 2: Manual Script Installation (Advanced)
For advanced users who prefer manual integration or need custom implementations.Option A: Header/Footer Plugin
- Install a plugin like “Insert Headers and Footers” or “WP Code”
- Go to Settings → Insert Headers and Footers
- In Scripts in Header, paste:
- Click Save
your-tenant-id with your actual tenant identifier!
Option B: Child Theme Functions.php
Add this to your child theme’sfunctions.php:
Custom Event Tracking
The plugin automatically tracks most events, but you can add custom tracking for specific use cases.Track Custom Events
Use the globalgrainTrack function (available when using the plugin or manual installation):
Track Blog Posts
Using the plugin? Blog posts are already tracked automatically with post ID, title, author, and categories. This is only needed for custom tracking scenarios.
Track Form Submissions
Contact Form 7:Track Search Queries
Using the plugin? Search queries are already tracked automatically. This is for custom implementations.
Track Comments
Using the plugin? Comment submissions are already tracked automatically.
WooCommerce Integration
Using the plugin? All WooCommerce events are tracked automatically! Product views, add to cart, checkout, and orders are handled out of the box. The examples below are for custom implementations only.
Automatic WooCommerce Tracking (Plugin)
When using the official Grain Analytics plugin, these events are tracked automatically:- ✅ Product views - with product ID, name, price, categories
- ✅ Add to cart - both standard and AJAX add to cart
- ✅ Remove from cart
- ✅ Cart views
- ✅ Checkout started
- ✅ Order completed - critical conversion event with order details
- ✅ Coupon applied/removed
- ✅ Quantity changes
Manual WooCommerce Tracking (Advanced)
For custom implementations or additional tracking: Track Custom Product Events:Test Your Integration
Using the Plugin
- Go to Settings → Grain Analytics in WordPress admin
- Click Send Test Event button at the bottom
- Check your Grain dashboard for the test event
- Navigate your site and verify events appear in real-time
Manual Testing
- Open your site in incognito/private window
- Open browser console (F12 → Console)
- Type
grainTrack— you should see the function - Navigate a few pages
- Check your Grain dashboard
Troubleshooting
Plugin Not Tracking
Check the basics:- Verify “Enable Tracking” is ON in Settings → Grain Analytics
- Check that your Tenant ID is correct
- Use the “Send Test Event” button to verify connection
- Clear your site cache (if using WP Rocket, W3 Total Cache, etc.)
- Check browser console for errors (F12 → Console)
- Enable “Exclude Admin Users” in plugin settings
- Log out and test in incognito mode
Script Not Loading
For manual installations:- Check PHP syntax (missing semicolons or quotes)
- Clear cache plugins
- Verify code is in
<head>section - Check theme.liquid or functions.php for errors
- Deactivate and reactivate the plugin
- Check for JavaScript conflicts with other plugins
- Ensure your site isn’t blocking the Grain CDN
Events Not in Dashboard
- Wait 1-2 minutes (slight processing delay is normal)
- Verify
grainTrackfunction exists in browser console - Check Network tab (F12) for outgoing requests to
*.grainql.com - Disable ad blockers and privacy extensions temporarily
- Verify your Tenant ID matches your dashboard
WooCommerce Events Missing
- Ensure WooCommerce is active and up to date
- Check that WooCommerce events are enabled in plugin settings
- Test add to cart and checkout in incognito mode
- Check browser console for JavaScript errors
Performance Issues
The plugin is highly optimized, but if you notice issues:- Enable “Async Loading” in plugin settings (if available)
- Ensure you’re using the latest plugin version
- Check for conflicts with optimization plugins (try excluding Grain script from optimization)
- Contact support if issues persist
What’s Next?
Shopify Integration
Running an online store? Check out Shopify integration
Event Tracking
Learn event tracking best practices
Tracks & Funnels
Analyze user journeys through your content
Query API
Build custom analytics dashboards
Plugin Support
- Plugin Issues: GitHub Issues
- Documentation: docs.grainql.com
- Dashboard: grainql.com/dashboard
- Email Support: [email protected]