public static function load_segment_api() { if (!class_exists('Analytics')) { require_once EDD_SEGMENT_PATH . '/lib/segment-php/lib/Segment.php'; class_alias('Segment', 'Analytics'); Analytics::init(self::$write_key); } }
/** * Load the default configuration settings */ public function __construct() { // Respect the customer's "Do Not Track" headers. $this->dnt = \Input::server('HTTP_DNT', 0) == 1 ? true : false; \Config::load('segment', true); \Analytics::init(\Config::get('segment.write_key'), \Config::get('segment.configure'), array()); /** * This also serves as something to check to see if Google Analytics is in use. Although the cookie could * be set through alternative means, such as a separate UA tracking code, sending the extra data won't hurt * anything. */ $this->_set_ga_cookie_id(); // Set the debug mode for JS $this->_js_debug = \Config::get('segment.configure.debug', false); $this->identity = \Session::get('segment.identity'); if (empty($this->identity)) { $this->identity = array('anonymousId' => $this->_generate_random_id()); \Session::set('segment.identity', $this->identity); } }
<?php require 'analytics-php/lib/Analytics.php'; $config = Config::get('analytics'); Analytics::init($config['segmentio-key']);
<?php /** * @link https://github.com/lordcoste/analytics-s2s * @author Colao Stefano < *****@*****.** > */ const BUNDLE_NAME = 'analytics-s2s'; Autoloader::map(array('Analytics' => Bundle::path(BUNDLE_NAME) . 'Analytics.php', 'AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'AnalyticsService.php', 'Google_Client' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'Google_Client.php', 'Google_AnalyticsService' => Bundle::path(BUNDLE_NAME) . 'google-api' . DS . 'contrib' . DS . 'Google_AnalyticsService.php')); IoC::singleton('google-analytics', function () { $prefix = Bundle::prefix(BUNDLE_NAME); if (!File::exists(Config::get($prefix . 'google.certificate_path'))) { throw new Exception("Can't find the .p12 certificate in: " . Config::get($prefix . 'google.certificate_path')); } $config = array('oauth2_client_id' => Config::get($prefix . 'google.client_id'), 'use_objects' => Config::get($prefix . 'google.use_objects')); $google = new Google_Client($config); $google->setAccessType('offline'); $google->setAssertionCredentials(new Google_AssertionCredentials(Config::get($prefix . 'google.service_email'), array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents(Config::get($prefix . 'google.certificate_path')))); return new AnalyticsService($google); }); Analytics::init(IoC::resolve('google-analytics'));
<?php /** * Initialize the library */ date_default_timezone_set('America/Los_Angeles'); require_once "./analytics/lib/Segment.php"; class_alias('Segment', 'Analytics'); Analytics::init("testsecret", array("debug" => true, "error_handler" => function ($code, $msg) { error_log("error_log: " . $code . " " . $msg); })); /** * Create a random user to identify. */ $user = "******" . rand(); Analytics::identify(array("userId" => $user, "traits" => array("name" => "Michael Bolton", "email" => "*****@*****.**"))); echo "User: {$user}";
function setUp() { Analytics::init("testsecret"); }