Skip to content

Instantly share code, notes, and snippets.

@hiltmon
Created July 19, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiltmon/d94ada6df376eef312e2d28c5c52e395 to your computer and use it in GitHub Desktop.
Save hiltmon/d94ada6df376eef312e2d28c5c52e395 to your computer and use it in GitHub Desktop.
GAPI Old to New Certificate Based PHP
OLD:
define('ga_email','hiltmon@gmail.com');
define('ga_password','i_aint_sayin');
define('which_profile',0); // The first profile
define('days_to_report', 7); // No of days excluding today!
define('ga_title','Hiltmon.com Stats');
require 'gapi.class.php';
date_default_timezone_set('America/New_York');
$ga = new gapi(ga_email,ga_password);
$ga->requestAccountData();
// Run this to see available accounts
// foreach($ga->getResults() as $result)
// {
// echo $result . ' (' . $result->getProfileId() . ")<br />";
// }
// And this to get the graph
$results = $ga->getResults();
$result = $results[which_profile];
$ga_profile_id = $result->getProfileId();
$start_date = date("Y-m-d", strtotime('-' . days_to_report . ' days'));
$end_date = date("Y-m-d");
...
NEW:
define('ga_title','Hiltmon.com Stats');
define('days_to_report', 7); // No of days excluding today!
define('ga_profile_id','XXXXXXXXX');
require 'gapi.class.php';
date_default_timezone_set('America/New_York');
$ga = new gapi('XXXXXXXXXX@developer.gserviceaccount.com', 'Noverse-GAPI-XXXXXXXXX.p12');
$start_date = date("Y-m-d", strtotime('-' . days_to_report . ' days'));
$end_date = date("Y-m-d");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment