Source for file analytics.php
Documentation is available at analytics.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE
* Google Analytics embed class for the Joomla Platform.
* @package Joomla.Platform
* Method to get the tracking code
* @return string The Google Analytics tracking code
* Method to set the tracking code
* @param string $code The Google Analytics tracking code
* @return JGoogleEmbedAnalytics The object for method chaining
* Checks if the javascript is set to be asynchronous
* @return boolean True if asynchronous
* Load javascript asynchronously
* @return JGoogleEmbedAnalytics The object for method chaining
* Load javascript synchronously
* @return JGoogleEmbedAnalytics The object for method chaining
* @param string $method The name of the function
* @param array $params The parameters for the call
* @return array The added call
public function addCall($method, $params =
array())
$call =
array('name' =>
$method, 'params' =>
$params);
* List the analytics calls to be executed
* @return array A list of calls
* Delete a call from the stack
* @param int $index Index of call to delete (defaults to last added call)
* @return array The deleted call
$index =
count($calls) -
1;
* Create a javascript function from the call parameters
* @param string $method The name of the function
* @param array $params The parameters for the call
* @return string The created call
public function createCall($method, $params =
array())
$output =
"_gaq.push(['{$method}',";
$output =
"pageTracker.{$method}(";
* Add a custom variable to the analytics
* @param int $slot The slot to store the variable in (1-5)
* @param string $name The variable name
* @param string $value The variable value
* @param int $scope The scope of the variable (1: visitor level, 2: session level, 3: page level)
* @return array The added call
public function addCustomVar($slot, $name, $value, $scope =
3)
return $this->addCall('_setCustomVar', array($slot, $name, $value, $scope));
* Get the code to create a custom analytics variable
* @param int $slot The slot to store the variable in (1-5)
* @param string $name The variable name
* @param string $value The variable value
* @param int $scope The scope of the variable (1: visitor level, 2: session level, 3: page level)
* @return string The created call
return $this->createCall('_setCustomVar', array($slot, $name, $value, $scope));
* Track an analytics event
* @param string $category The general event category
* @param string $action The event action
* @param string $label The event description
* @param string $value The value of the event
* @param boolean $noninteract Don't allow this event to impact bounce statistics
* @return array The added call
public function addEvent($category, $action, $label =
null, $value =
null, $noninteract =
false)
return $this->addCall('_trackEvent', array($category, $action, $label, $value, $noninteract));
* Get the code to track an analytics event
* @param string $category The general event category
* @param string $action The event action
* @param string $label The event description
* @param string $value The value of the event
* @param boolean $noninteract Don't allow this event to impact bounce statistics
* @return string The created call
public function createEvent($category, $action, $label =
null, $value =
null, $noninteract =
false)
return $this->createCall('_trackEvent', array($category, $action, $label, $value, $noninteract));
* Get code to load Google Analytics javascript
* @return string Javascript code
// Synchronous code is included only in the body
throw
new UnexpectedValueException('A Google Analytics tracking code is required.');
$output =
'<script type="text/javascript">';
$output .=
'var _gaq = _gaq || [];';
$output .=
"_gaq.push(['_setAccount', '{$code}']);";
$output .=
$this->createCall($call['name'], $call['params']);
$output .=
'_gaq.push(["_trackPageview"]);';
* Google Analytics only needs to be included in the header
throw
new UnexpectedValueException('A Google Analytics tracking code is required.');
$prefix =
$this->isSecure() ?
'https://ssl' :
'http://www';
$output =
'<script type="text/javascript">';
$output .=
'(function() {';
$output .=
'var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;';
$output .=
"ga.src = '{$prefix}.google-analytics.com/ga.js';";
$output .=
'var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);';
$output =
'<script type="text/javascript">';
$output .=
"document.write(unescape(\"%3Cscript src='{$prefix}.google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));";
$output .=
'<script type="text/javascript">';
$output .=
"var pageTracker = _gat._getTracker('{$code}');";
$output .=
$this->createCall($call['name'], $call['params']);
$output .=
'pageTracker._trackPageview();';
$output .=
'} catch(err) {}</script>';
Documentation generated on Tue, 19 Nov 2013 14:53:41 +0100 by phpDocumentor 1.4.3