Skip to content

Commit f3c6d0e

Browse files
committedNov 27, 2019
GA Reporting draft
1 parent 6112803 commit f3c6d0e

File tree

7 files changed

+732
-4
lines changed

7 files changed

+732
-4
lines changed
 

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ composer.phar
44
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
55
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
66
# composer.lock
7-
.env
7+
.env
8+
google-credentials.json

‎bin/etl.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AdsWarehouse;
4+
5+
use AdsWarehouse\ETL\GoogleAnalytics;
6+
use Google_Client;
7+
use Google_Service_Analytics;
8+
use Google_Service_AnalyticsReporting;
9+
use Monolog\Handler\ErrorLogHandler;
10+
use PDO;
11+
use Siler\Monolog as Log;
12+
13+
$basedir = dirname(__DIR__, 1);
14+
require_once "$basedir/vendor/autoload.php";
15+
16+
Log\handler(new ErrorLogHandler());
17+
18+
$pdo = new PDO(getenv('POSTGRES_DSN'));
19+
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::ERRMODE_EXCEPTION);
20+
21+
$context = new Context();
22+
$context->warehouse = new Warehouse\Pdo($pdo);
23+
24+
$google_client = new Google_Client();
25+
$google_client->setApplicationName('Ads Warehouse');
26+
$google_client->setAuthConfig($basedir . DIRECTORY_SEPARATOR . getenv('GOOGLE_CREDENTIALS'));
27+
$google_client->setScopes([Google_Service_Analytics::ANALYTICS_READONLY]);
28+
29+
$analytics = new Google_Service_AnalyticsReporting($google_client);
30+
$analytics_etl = new GoogleAnalytics($context->warehouse, $analytics, getenv('GA_VIEW_ID'));
31+
32+
$analytics_etl->load();

‎composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"leocavalcante/siler": "dev-master",
88
"monolog/monolog": "^2.0",
99
"firebase/php-jwt": "^5.0",
10-
"webonyx/graphql-php": "^0.13.8"
10+
"webonyx/graphql-php": "^0.13.8",
11+
"google/apiclient": "^2.4"
1112
},
1213
"require-dev": {
1314
"swoole/ide-helper": "^4.4",
@@ -27,5 +28,9 @@
2728
"src/"
2829
]
2930
}
31+
},
32+
"scripts": {
33+
"up": "docker-compose up",
34+
"etl": "docker-compose exec -T server php bin/etl.php"
3035
}
3136
}

0 commit comments

Comments
 (0)
Please sign in to comment.