Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite adding support for namespacing, UTMV cookie and unit testings. #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Installation:

Clone this repository, and include autoload.php. If you are using another
autoloader, simply point it to the GoogleAnalytics namespace in the "src"
directory.

Usage:

The Google Analytics UTM Variables typycally available as cookies. If you are tracking accross domains (using _getLinkerUrl()), these parameters will initially be available via the HTTP_REFERER query string.

This library is currently able to process the following cookies:

__utma - Expires 2 years after set/update. Stores Domain Hash, Visitor ID and a series of timestamps.
__utmb - Expires 30 mins from set/update. This is used to determine session expiration.
__utmc - Expires at the end of browser session. Deprecated.
__utmv - Expires 2 years from set/update. Stores Custom Variables.
__utmz - Expires 6 months from set/update. Stores campaign attribution information.

```php
<?php

$tracker = new \GoogleAnalytics\CampaignTracking\Tracker($_COOKIE);

echo $tracker->getCampaignMedium() . "\n";
echo $tracker->getCampaignSource() . "\n";
```

Wish List:

1) First and foremost, the regular expressions used in the "validate" methods
need to be improved upon.

2) I would like to implement ArrayAcces, Serializable and JsonSerializable.
One thing that will have to be decided is how to handle the timestamps.
All the timestamps are currently transformed into DateTime objects. For
ArrayAccess, we could return a string or the DateTime object. For the
serializing interfaces, we will certainly want a string, but a decision
will have to be made as to what format (ie. UNIX Timestamp, ISO8601, etc).
So...
2a) Implement ArrayAccess for Tracker, CustomVar and Utm classes.
2b) Implement Serializable for Tracker, CustomVar and Utm classes.
2c) Implement JsonSerializable for Tracker, CustomVar and Utm classes.

3) Implement some sort of toArray() functionality for the whole model.
22 changes: 0 additions & 22 deletions Readme.md

This file was deleted.

7 changes: 7 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if(!class_exists('SplClassLoader'))
require __DIR__.'/lib/SplClassLoader.php';

$_classLoader = new \SplClassLoader('GoogleAnalytics', __DIR__.'/src');
$_classLoader->register();
95 changes: 0 additions & 95 deletions class.gaparse.php

This file was deleted.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "RogerWebb/Google-Analytics-PHP-cookie-parser"
}
33 changes: 0 additions & 33 deletions example.php

This file was deleted.

136 changes: 136 additions & 0 deletions lib/SplClassLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
* $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine');
* $classLoader->register();
*
* @author Jonathan H. Wage <[email protected]>
* @author Roman S. Borschel <[email protected]>
* @author Matthew Weier O'Phinney <[email protected]>
* @author Kris Wallsmith <[email protected]>
* @author Fabien Potencier <[email protected]>
*/
class SplClassLoader
{
private $_fileExtension = '.php';
private $_namespace;
private $_includePath;
private $_namespaceSeparator = '\\';

/**
* Creates a new <tt>SplClassLoader</tt> that loads classes of the
* specified namespace.
*
* @param string $ns The namespace to use.
*/
public function __construct($ns = null, $includePath = null)
{
$this->_namespace = $ns;
$this->_includePath = $includePath;
}

/**
* Sets the namespace separator used by classes in the namespace of this class loader.
*
* @param string $sep The separator to use.
*/
public function setNamespaceSeparator($sep)
{
$this->_namespaceSeparator = $sep;
}

/**
* Gets the namespace seperator used by classes in the namespace of this class loader.
*
* @return void
*/
public function getNamespaceSeparator()
{
return $this->_namespaceSeparator;
}

/**
* Sets the base include path for all class files in the namespace of this class loader.
*
* @param string $includePath
*/
public function setIncludePath($includePath)
{
$this->_includePath = $includePath;
}

/**
* Gets the base include path for all class files in the namespace of this class loader.
*
* @return string $includePath
*/
public function getIncludePath()
{
return $this->_includePath;
}

/**
* Sets the file extension of class files in the namespace of this class loader.
*
* @param string $fileExtension
*/
public function setFileExtension($fileExtension)
{
$this->_fileExtension = $fileExtension;
}

/**
* Gets the file extension of class files in the namespace of this class loader.
*
* @return string $fileExtension
*/
public function getFileExtension()
{
return $this->_fileExtension;
}

/**
* Installs this class loader on the SPL autoload stack.
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
}

/**
* Uninstalls this class loader from the SPL autoloader stack.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}

/**
* Loads the given class or interface.
*
* @param string $className The name of the class to load.
* @return void
*/
public function loadClass($className)
{
if (null === $this->_namespace || $this->_namespace.$this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace.$this->_namespaceSeparator))) {
$fileName = '';
$namespace = '';
if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension;

require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName;
}
}
}
7 changes: 7 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<phpunit bootstrap="autoload.php">
<testsuites>
<testsuite name="GoogleAnalytics">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
Loading