Simply copy and paste these PHP functions onto your site to enable Google Analytics data using only your server-side code. Special thanks to stumiller.me for his research- I’ve customized some of his functions to work on any WordPress (or other PHP) website.
Be sure to change the Google Analytics tracking ID to your own in both places!
Now that you have the utility functions in place, all you have to do is call one of the following to send data. To send a pageview, use this syntax:
ga_send_pageview($hostname, $page, $title);
ga_send_pageview('gearside.com', 'http://gearside.com/nebula/', 'Nebula by Gearside');
To send an event, use this syntax:
ga_send_pageview($category, $action, $label);
ga_send_pageview('Contact Form', 'Submit', 'Feature Request');
- Security precautions (Login tampering, spambot prevention, or direct template access attempts)
- AJAX functions