Add one or more Google Analytics trackers to your website.
Screenshots
Default settings with 1 tracker and the script printed in wp_footer()
Using multiple trackers and the custom hook for printing the script
FAQ
Installation Instructions
- Move the
ahr-google-analytics
folder to the /wp-content/plugins/
directory OR search for ‘Multiple Google Analytics’ and add the plugin using WordPress’ plugin browser.
- Activate the plugin through the ‘Plugins’ page in WordPress
- Add one or more web property IDs (UA-XXXXXXX-X strings) on the settings page
What is a Google Analytics property ID?
It’s the string looking like UA-XXXXXXX-X
next to your website URL on https://analytics.google.com/analytics/web/
JavaScript: How do I track pageviews/events/etc. using multiple trackers
If you’re building a JavaScript-based web app and manually need to track custom routes or events you can use the ga.getAll()
method to get an array of registered trackers and then run the tracking logic for each tracker.
For example, this will track page views based on custom routes:
if ( typeof ga === 'function' && typeof ga.getAll === 'function' ) {
ga.getAll().forEach(tracker => {
tracker.set('page', *my-custom-route*); // Custom route e.g. '/my-page'
tracker.send('pageview');
})
}
And here’s an example of tracking custom events:
if ( typeof ga === 'function' && typeof ga.getAll === 'function' ) {
ga.getAll().forEach(tracker => {
tracker.send('event', {
eventCategory: 'Search',
eventAction: 'Query',
eventLabel: *query*, // Your search query
eventValue: *matches.length* // Optionally, send the number of matches for the query
});
})
}
ChangeLog
1.1.2
Release Date: September 11th, 2017
Add support for the new longer google analytics ID’s that would previously be rejected by the validator
1.1.1
Release Date: March 15th, 2017
Fixes a bug where default values weren’t set properly when first activating plugin
1.0.1
Release Date: December 11th, 2016
Fixes typos in plugin activation/deactivation callback functions
1.0.0
Release Date: November 2nd, 2016