Skip to content

Commit

Permalink
Added support for sending page information with events
Browse files Browse the repository at this point in the history
Thanks to patches from GlaserFrank & ryan.mcgarrie
(https://code.google.com/p/php-ga/issues/detail?id=16)
  • Loading branch information
thomasbachem committed Oct 6, 2013
1 parent 8097ce3 commit fea7709
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/GoogleAnalytics/Internals/Request/EventRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
namespace UnitedPrototype\GoogleAnalytics\Internals\Request;

use UnitedPrototype\GoogleAnalytics\Event;
use UnitedPrototype\GoogleAnalytics\Page;

use UnitedPrototype\GoogleAnalytics\Internals\X10;

Expand Down Expand Up @@ -86,6 +87,17 @@ protected function buildParameters() {
if($this->event->getNoninteraction()) {
$p->utmni = 1;
}

if($this->page) {
$p->utmp = $this->page->getPath();
$p->utmdt = $this->page->getTitle();
if($this->page->getCharset() !== null) {
$p->utmcs = $this->page->getCharset();
}
if($this->page->getReferrer() !== null) {
$p->utmr = $this->page->getReferrer();
}
}

return $p;
}
Expand All @@ -104,6 +116,20 @@ public function setEvent(Event $event) {
$this->event = $event;
}

/**
* @return \UnitedPrototype\GoogleAnalytics\Page
*/
public function getPage() {
return $this->page;
}

/**
* @param \UnitedPrototype\GoogleAnalytics\Page $page
*/
public function setPage(Page $page) {
$this->page = $page;
}

}

?>
6 changes: 5 additions & 1 deletion src/GoogleAnalytics/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,19 @@ public function trackPageview(Page $page, Session $session, Visitor $visitor) {
* @param \UnitedPrototype\GoogleAnalytics\Event $event
* @param \UnitedPrototype\GoogleAnalytics\Session $session
* @param \UnitedPrototype\GoogleAnalytics\Visitor $visitor
* @param \UnitedPrototype\GoogleAnalytics\Page $page
*/
public function trackEvent(Event $event, Session $session, Visitor $visitor) {
public function trackEvent(Event $event, Session $session, Visitor $visitor, Page $page = null) {
// Ensure that all required parameters are set
$event->validate();

$request = new EventRequest(static::$config);
$request->setEvent($event);
$request->setSession($session);
$request->setVisitor($visitor);
if($page) {
$request->setPage($page);
}
$request->setTracker($this);
$request->fire();
}
Expand Down

0 comments on commit fea7709

Please sign in to comment.