diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2014-09-13 17:34:58 +0400 |
---|---|---|
committer | Thomas Steur <tsteur@users.noreply.github.com> | 2014-09-13 17:34:58 +0400 |
commit | ddf202a0c9e4f0a65c43d2daa94aaedec1541c53 (patch) | |
tree | 03cfe402323e6699aa1743de5231eae8763c02aa /libs | |
parent | 07291cd4a383a8ccc396a5350563e70be1a7a1e7 (diff) | |
parent | 980ac3aeaa50eb7a14b473534861a69324f36c2e (diff) |
Merge pull request #6201 from piwik/4996_content_tracking
Content Tracking
Diffstat (limited to 'libs')
-rw-r--r-- | libs/PiwikTracker/PiwikTracker.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/libs/PiwikTracker/PiwikTracker.php b/libs/PiwikTracker/PiwikTracker.php index aec4d011a4..8605e38e1f 100644 --- a/libs/PiwikTracker/PiwikTracker.php +++ b/libs/PiwikTracker/PiwikTracker.php @@ -554,6 +554,36 @@ class PiwikTracker } /** + * Tracks a content impression + * + * @param string $contentName The name of the content. For instance 'Ad Foo Bar' + * @param string $contentPiece The actual content. For instance the path to an image, video, audio, any text + * @param string|false $contentTarget (optional) The target of the content. For instance the URL of a landing page. + * @return mixed Response string or true if using bulk requests. + */ + public function doTrackContentImpression($contentName, $contentPiece = 'Unknown', $contentTarget = false) + { + $url = $this->getUrlTrackContentImpression($contentName, $contentPiece, $contentTarget); + return $this->sendRequest($url); + } + + /** + * Tracks a content interaction. Make sure you have tracked a content impression using the same content name and + * content piece, otherwise it will not count. To do so you should call the method doTrackContentImpression(); + * + * @param string $interaction The name of the interaction with the content. For instance a 'click' + * @param string $contentName The name of the content. For instance 'Ad Foo Bar' + * @param string $contentPiece The actual content. For instance the path to an image, video, audio, any text + * @param string|false $contentTarget (optional) The target the content leading to when an interaction occurs. For instance the URL of a landing page. + * @return mixed Response string or true if using bulk requests. + */ + public function doTrackContentInteraction($interaction, $contentName, $contentPiece = 'Unknown', $contentTarget = false) + { + $url = $this->getUrlTrackContentInteraction($interaction, $contentName, $contentPiece, $contentTarget); + return $this->sendRequest($url); + } + + /** * Tracks an internal Site Search query, and optionally tracks the Search Category, and Search results Count. * These are used to populate reports in Actions > Site Search. * @@ -852,6 +882,72 @@ class PiwikTracker } /** + * Builds URL to track a content impression. + * + * @see doTrackContentImpression() + * @param string $contentName The name of the content. For instance 'Ad Foo Bar' + * @param string $contentPiece The actual content. For instance the path to an image, video, audio, any text + * @param string|false $contentTarget (optional) The target of the content. For instance the URL of a landing page. + * @throws Exception In case $contentName is empty + * @return string URL to piwik.php with all parameters set to track the pageview + */ + public function getUrlTrackContentImpression($contentName, $contentPiece, $contentTarget) + { + $url = $this->getRequest($this->idSite); + + if (strlen($contentName) == 0) { + throw new Exception("You must specify a content name"); + } + + $url .= '&c_n=' . urlencode($contentName); + + if (!empty($contentPiece) && strlen($contentPiece) > 0) { + $url .= '&c_p=' . urlencode($contentPiece); + } + if (!empty($contentTarget) && strlen($contentTarget) > 0) { + $url .= '&c_t=' . urlencode($contentTarget); + } + + return $url; + } + + /** + * Builds URL to track a content impression. + * + * @see doTrackContentInteraction() + * @param string $interaction The name of the interaction with the content. For instance a 'click' + * @param string $contentName The name of the content. For instance 'Ad Foo Bar' + * @param string $contentPiece The actual content. For instance the path to an image, video, audio, any text + * @param string|false $contentTarget (optional) The target the content leading to when an interaction occurs. For instance the URL of a landing page. + * @throws Exception In case $interaction or $contentName is empty + * @return string URL to piwik.php with all parameters set to track the pageview + */ + public function getUrlTrackContentInteraction($interaction, $contentName, $contentPiece, $contentTarget) + { + $url = $this->getRequest($this->idSite); + + if (strlen($interaction) == 0) { + throw new Exception("You must specify a name for the interaction"); + } + + if (strlen($contentName) == 0) { + throw new Exception("You must specify a content name"); + } + + $url .= '&c_i=' . urlencode($interaction); + $url .= '&c_n=' . urlencode($contentName); + + if (!empty($contentPiece) && strlen($contentPiece) > 0) { + $url .= '&c_p=' . urlencode($contentPiece); + } + if (!empty($contentTarget) && strlen($contentTarget) > 0) { + $url .= '&c_t=' . urlencode($contentTarget); + } + + return $url; + } + + /** * Builds URL to track a site search. * * @see doTrackSiteSearch() |