Skip to content

Commit

Permalink
Merge pull request #24 from ins0/feature/qt-param
Browse files Browse the repository at this point in the history
Feature/qt param
  • Loading branch information
ins0 committed Nov 16, 2015
2 parents 33fc1f7 + 52a2455 commit 9e15029
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Racecore/GATracking/Tracking/AbstractTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ abstract class AbstractTracking

private $customPayload = array();

// event queue time difference
private $queueTime;

/**
* Add Custom Tracking Payload Data send to Google
* @param $key
Expand Down Expand Up @@ -196,6 +199,9 @@ public function getPackage()
// content experiments
'xid' => $this->experimentID,
'xvar' => $this->experimentVariant,

// optional
'qt' => $this->queueTime,
));

$package = $this->addCustomParameters($package);
Expand All @@ -209,6 +215,19 @@ public function getPackage()
return $package;
}

/**
* Set the Tracking Processing Time to pass the qt param within this tracking request
* ATTENTION!: Values greater than four hours may lead to hits not being processed.
*
* https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt
*
* @param $milliseconds
*/
public function setQueueTime($milliseconds)
{
$this->queueTime = $milliseconds;
}

/**
* Mark the Hit as Non Interactive
*
Expand Down
26 changes: 26 additions & 0 deletions test/Racecore/GATracking/Tracking/TrackingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Racecore\GATracking\Tracking;

use Racecore\GATracking\AbstractGATrackingTest;

/**
* Class TrackingTest
*
* @package Racecore\GATracking\Tracking
*/
class TrackingTest extends AbstractGATrackingTest
{
public function testCanSetTrackingProcessingTime()
{
$queueTime = 12345678;

$event = new Event();
$event->setEventCategory('foo');
$event->setEventAction('bar');
$event->setQueueTime($queueTime);

$package = $event->getPackage();
$this->assertEquals($queueTime, $package['qt']);
}
}

0 comments on commit 9e15029

Please sign in to comment.