Created
January 21, 2015 06:32
-
-
Save hamaguchi/c7ff168689d8b902ca14 to your computer and use it in GitHub Desktop.
GoogleAnalytics_track
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* GoogleanAlyticsトラッキングを、PHPで強引に送信する | |
* | |
* @param type $long_url | |
* @param type $title | |
* @param type $remote_addr | |
* @param type $http_user_agent | |
*/ | |
public static function googleanalytics_track($long_url, $title, $remote_addr, $http_user_agent) | |
{ | |
// Initilize GA Tracker | |
$tracker = new GoogleAnalytics\Tracker(\Config::get('googleanalytics.key'), \Config::get('googleanalytics.domain')); | |
// Assemble Visitor information | |
// (could also get unserialized from database) | |
$visitor = new GoogleAnalytics\Visitor(); | |
$visitor->setIpAddress($remote_addr); | |
$visitor->setUserAgent($http_user_agent); | |
// Assemble Session information | |
// (could also get unserialized from PHP session) | |
$session = new GoogleAnalytics\Session(); | |
// Assemble Page information | |
$page = new GoogleAnalytics\Page(str_replace("http://", "/", $long_url)); | |
$page->setTitle($title); | |
// Track page view | |
$tracker->trackPageview($page, $session, $visitor); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment