Skip to content

Commit

Permalink
Implemented "non-interaction" parameter for event tracking, updated t…
Browse files Browse the repository at this point in the history
…racker version to 5.2.2

git-svn-id: http://php-ga.googlecode.com/svn/trunk@28 edaf56f0-51c5-75dc-8b6c-d0dc49a406ca
  • Loading branch information
mail@thomasbachem.com committed Nov 15, 2011
1 parent a50f968 commit 36c7081
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
45 changes: 40 additions & 5 deletions src/GoogleAnalytics/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,62 @@

/**
* @link http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
*/
class Event {

/**
* The general event category (e.g. "Videos").
*
* @var string
*/
protected $category;

/**
* The action for the event (e.g. "Play").
*
* @var string
*/
protected $action;

/**
* An optional descriptor for the event (e.g. the video's title).
*
* @var string
*/
protected $label;

/**
* An optional value associated with the event. You can see your event values in the Overview,
* Categories, and Actions reports, where they are listed by event or aggregated across events,
* depending upon your report view.
*
* @var int
*/
protected $value;

/**
* Default value is false. By default, event hits will impact a visitor's bounce rate.
* By setting this parameter to true, this event hit will not be used in bounce rate calculations.
*
* @var bool
*/
protected $noninteraction = false;


/**
* @param string $category
* @param string $action
* @param string $label
* @param int $value
* @param bool $noninteraction
*/
public function __construct($category = null, $action = null, $label = null, $value = null) {
if($category !== null) $this->setCategory($category);
if($action !== null) $this->setAction($action);
if($label !== null) $this->setLabel($label);
if($value !== null) $this->setValue($value);
public function __construct($category = null, $action = null, $label = null, $value = null, $noninteraction = null) {
if($category !== null) $this->setCategory($category);
if($action !== null) $this->setAction($action);
if($label !== null) $this->setLabel($label);
if($value !== null) $this->setValue($value);
if($noninteraction !== null) $this->setNoninteraction($noninteraction);
}

public function validate() {
Expand Down Expand Up @@ -129,6 +150,20 @@ public function setValue($value) {
$this->value = (int)$value;
}

/**
* @return bool
*/
public function getNoninteraction() {
return $this->noninteraction;
}

/**
* @param bool $value
*/
public function setNoninteraction($value) {
$this->noninteraction = (bool)$value;
}

}

?>
8 changes: 8 additions & 0 deletions src/GoogleAnalytics/Internals/ParameterHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ class ParameterHolder {
*/
public $utme;

/**
* Event "non-interaction" parameter. By default, the event hit will impact a visitor's bounce rate.
* By setting this parameter to 1, this event hit will not be used in bounce rate calculations.
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
* @var int
*/
public $utmni;

/**
* Whether to anonymize IP addresses within Google Analytics by stripping
* the last IP address block, either null or 1
Expand Down
4 changes: 4 additions & 0 deletions src/GoogleAnalytics/Internals/Request/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ protected function buildParameters() {

$p->utme .= $x10->renderUrlString();

if($this->event->getNoninteraction()) {
$p->utmni = 1;
}

return $p;
}

Expand Down
32 changes: 30 additions & 2 deletions src/GoogleAnalytics/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ class Tracker {

/**
* Google Analytics client version on which this library is built upon,
* will be mapped to "utmwv" parameter
* will be mapped to "utmwv" parameter.
*
* This doesn't necessarily mean that all features of the corresponding
* ga.js version are implemented but rather that the requests comply
* with these of ga.js.
*
* @link http://code.google.com/apis/analytics/docs/gaJS/changelog.html
* @const string
*/
const VERSION = '4.9.2';
const VERSION = '5.2.2'; // As of 15.11.2011


/**
Expand Down Expand Up @@ -85,6 +89,11 @@ class Tracker {
*/
protected $customVariables = array();

/**
* @var \UnitedPrototype\GoogleAnalytics\Campaign
*/
protected $campaign;


/**
* @param string $accountId
Expand Down Expand Up @@ -188,6 +197,25 @@ public function removeCustomVariable($index) {
unset($this->customVariables[$index]);
}

/**
* @param \UnitedPrototype\GoogleAnalytics\Campaign $campaign
*/
public function setCampaign(Campaign $campaign = null) {
if($campaign) {
// Ensure that all required parameters are set
$campaign->validate();
}

$this->campaign = $campaign;
}

/**
* @return \UnitedPrototype\GoogleAnalytics\Campaign|null
*/
public function getCampaign() {
return $this->campaign;
}

/**
* Equivalent of _trackPageview() in GA Javascript client.
*
Expand Down

0 comments on commit 36c7081

Please sign in to comment.