Last active
August 29, 2015 14:17
-
-
Save hamaguchi/7aeaaba827a748aa867d to your computer and use it in GitHub Desktop.
[PHP] Google Analytics のアクセス偽装方法を実装してみる [FuelPHP] ref: http://qiita.com/makoto1899/items/b15bc608484a19c0a48e
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); | |
} |
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); | |
} |
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
$visitor->setScreenResolution('1024x768'); |
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
$visitor->setScreenColorDepth('32-bit'); |
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
$page->setReferrer($referrer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment