Code Monkey home page Code Monkey logo

google-analytics-measurement-protocol-php's Introduction

Google Analytics Measurement Protocol PHP

Google Analytics Measurement Protocol library implementation for PHP

Usage

1) Instance GAMP class

$classGamp = new Gamp\Gamp();

2) Set required general parameters for Payload

$cGeneral = new \Gamp\PayloadParamGroups\General();
$cGeneral->setV(1);
$cGeneral->setTid('UA-27773588-3');
$classGamp->addGroup($cGeneral);

$cUser = new \Gamp\PayloadParamGroups\User();
$cUser->setCid($cUser->getCidNumber());
$classGamp->addGroup($cUser);

3) Set required HIT parameters for Payload

$cHit = new \Gamp\PayloadParamGroups\Hit();
$cHit->setT('event'); //Event type
$classGamp->addGroup($cHit);

$cEvent = new \Gamp\PayloadParamGroups\Event();
$cEvent->setEc('Download');
$cEvent->setEa('Some product name');
$cEvent->setEl('Some URL');
$classGamp->addGroup($cEvent);

4) Set another parameters - depends on your needs

4a) Example custom dimensions
$cCustomDimension = new \Gamp\PayloadParamGroups\CustomDimension();
$cCustomDimension->setCd('1', 'TEST-001-A');
$cCustomDimension->setCd('2', 'Some product name');
$cCustomDimension->setCd('3', 'Some URL');
$classGamp->addGroup($cCustomDimension);

5) Process tracking request

5a) Set request type
$classGamp->setRequestType('POST');
5b) Remove not used (unset) parameters from request
$classGamp->setFiltered(true);
5c) Set protocol
$classGamp->setRequestProtocol('SSL');
5c) Execute request
$classGamp->track();

google-analytics-measurement-protocol-php's People

Contributors

mirekratman avatar

Stargazers

Trevor Bice avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.