Blog

google analytics

Google Analytics PHP Server Side Tracking

Most of us tend to use Google Analytics with JavaScript for a simple and effective way of tracking our users interactions. However there are times where we need to do some tracking on the server side and Google does provide a server side tracking API. All of the normal analytics tracking tools are available via HTTP requests, and thanks to user Dan Cameron on Github, we also have a wrapper that will allow us to easily implement server side event tracking with PHP.

To get things setup, you will first need to download the class here.

Once you have downloaded it, place it in a directory that you can access and include it on the file you are wanting to track.

Next, you will need to create an object with your Google analytics account id.

If you would just like to send a “page view” then all you will need to do is the following:

Simple. Next, if you would like to setup some event tracking, then you will add the following:

That will send an event to your GA account and that’s it. You’re done! Google Analytics on the server side is now possible!

Questions? Comments? Leave a note in the comments below or reach out us at [email protected] Follow us on Facebook and Twitter for more nonprofit marketing tips, and sign up for our newsletter for a monthly update from our nonprofit marketing pros!

San Francisco

147 Natoma Street
San Francisco, CA 94105
(415) 938-6398

Washington D.C.

641 S Street NW
Washington D.C. 20001

Atlanta

800 Battery Ave SE, Suite 100,
Atlanta, GA 30339

Boston

170 Milk Street, 5th Floor
Boston, MA 02109
(617) 804-0861