Skip to content

Simple PHP client wrapper class for the GA Measurement Protocol v1

Notifications You must be signed in to change notification settings

reconstrukt/ga-measurement-protocol-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

GA Measurement Protocol PHP Client

Simple client wrapper class for the GA Measurement Protocol v1. Requires curl.

Features

  • Server-side pageview and event tracking with GA
  • Associates server-side events to a current GA session's client ID, by parsing 'clientId' from _ga cookie (if exists)
  • Supports debug mode for GA's hit validation endpoint
  • Does not handle batch payloads, yet

Usage

Pretty straightforward, just drop in and go.

<?php
// drop in the class
require_once 'lib/gamp.php';

// init with your GA Site ID
$gamp = new gamp( 'UA-XXXXXXXX-X' );

// set pageview
(bool) $hit = $gamp->pageview( '/url/to/track', 'My Page Title' );

// set event
(bool) $hit = $gamp->event( 'Test', 'GAMP-Event-Hit' );

Also supports a 'debug' option, based on GA's hit validation docs.

Usage:

<?php
require_once 'lib/gamp.php';
$gamp = new gamp( 'UA-XXXXXXXX-X' );

// I can haz debug
$gamp->debug = true;

// set pageview + event
$hit = $gamp->pageview();
$hit = $gamp->event( 'Test', 'GAMP-Event-Hit' );

// wassup 
print_r( $gamp->log );

About

Simple PHP client wrapper class for the GA Measurement Protocol v1

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages