Skip to content

Commit 36af68d

Browse files
committed
Saving some data from AdWords
1 parent 55e8d8e commit 36af68d

File tree

9 files changed

+336
-94
lines changed

9 files changed

+336
-94
lines changed

bin/etl.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace AdsWarehouse;
44

5-
use AdsWarehouse\ETL\GoogleAnalytics;
5+
use AdsWarehouse\ETL\AdWords;
6+
use AdsWarehouse\ETL\ETL;
67
use Google_Client;
78
use Google_Service_Analytics;
89
use Google_Service_AnalyticsReporting;
@@ -17,16 +18,19 @@
1718

1819
$pdo = new PDO(getenv('POSTGRES_DSN'));
1920
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::ERRMODE_EXCEPTION);
20-
21-
$context = new Context();
22-
$context->warehouse = new Warehouse\Pdo($pdo);
21+
$warehouse = new Warehouse\Pdo($pdo);
2322

2423
$google_client = new Google_Client();
2524
$google_client->setApplicationName('Ads Warehouse');
2625
$google_client->setAuthConfig($basedir . DIRECTORY_SEPARATOR . getenv('GOOGLE_CREDENTIALS'));
2726
$google_client->setScopes([Google_Service_Analytics::ANALYTICS_READONLY]);
2827

2928
$analytics = new Google_Service_AnalyticsReporting($google_client);
30-
$analytics_etl = new GoogleAnalytics($context->warehouse, $analytics, getenv('GA_VIEW_ID'));
3129

32-
$analytics_etl->load();
30+
$elt = [
31+
new AdWords($warehouse, $analytics, getenv('GA_VIEW_ID')),
32+
];
33+
34+
array_walk($elt, function (ETL $etl): void {
35+
$etl->load();
36+
});

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"monolog/monolog": "^2.0",
99
"firebase/php-jwt": "^5.0",
1010
"webonyx/graphql-php": "^0.13.8",
11-
"google/apiclient": "^2.4"
11+
"google/apiclient": "^2.4",
12+
"ramsey/uuid": "^3.8"
1213
},
1314
"require-dev": {
1415
"swoole/ide-helper": "^4.4",
@@ -30,7 +31,6 @@
3031
}
3132
},
3233
"scripts": {
33-
"up": "docker-compose up",
3434
"etl": "docker-compose exec -T server php bin/etl.php"
3535
}
3636
}

composer.lock

Lines changed: 186 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Ad/Ad.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
namespace AdsWarehouse\Ad;
44

5+
use DateTime;
6+
57
class Ad
68
{
79
/** @var string */
810
public $id;
911
/** @var string */
1012
public $name;
13+
/** @var float */
14+
public $cost;
15+
/** @var int */
16+
public $impressions;
17+
/** @var int */
18+
public $clicks;
19+
/** @var float */
20+
public $cpm;
21+
/** @var float */
22+
public $cpc;
23+
/** @var float */
24+
public $ctr;
25+
/** @var string */
26+
public $source;
27+
/** @var DateTime */
28+
public $date;
29+
30+
public function __construct()
31+
{
32+
if (isset($this->date) && is_string($this->date)) {
33+
$this->date = DateTime::createFromFormat('Y-m-d', $this->date);
34+
}
35+
}
1136
}

src/Ad/V1__Ad.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
create table ad
22
(
3-
id uuid not null primary key,
4-
name varchar not null,
5-
timestamp timestamp not null default current_timestamp
6-
);
3+
id uuid not null primary key,
4+
name varchar not null,
5+
cost float not null default 0,
6+
impressions int not null default 0,
7+
clicks int not null default 0,
8+
cpm float not null default 0,
9+
cpc float not null default 0,
10+
ctr float not null default 0,
11+
source varchar not null,
12+
date date not null,
13+
timestamp timestamp not null default current_timestamp
14+
);

0 commit comments

Comments
 (0)