forked from lordcoste/analytics-s2s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
45 lines (35 loc) · 1.47 KB
/
start.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @link https://github.com/lordcoste/analytics-s2s
* @author Colao Stefano < [email protected] >
*/
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'));