Skip to content

Commit 0cea77b

Browse files
authored
Add track revenue (#19)
1 parent 2fed15c commit 0cea77b

31 files changed

+983
-371
lines changed

src/Builders/Payload/EventSendPayloadBuilder.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Builders/Payload/ExperimentRunPayloadBuilder.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ class ExperimentRunPayloadBuilder
1111
public function build(string $userSignature, string $experimentId): JsonPayload
1212
{
1313
return new JsonPayload([
14-
'data' => [
15-
'type' => 'experiment-run',
16-
'attributes' => [
17-
'userSignature' => $userSignature,
18-
],
19-
'relationships' => [
20-
'experiment' => [
21-
'data' => [
22-
'id' => $experimentId,
23-
'type' => 'experiments',
24-
],
25-
],
26-
]
14+
'data' => [
15+
'type' => 'experiment-run',
16+
'attributes' => [
17+
'userSignature' => $userSignature,
2718
],
19+
'relationships' => [
20+
'experiment' => [
21+
'data' => [
22+
'id' => $experimentId,
23+
'type' => 'experiments',
24+
],
25+
],
26+
]
27+
],
2828
]);
2929
}
3030
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Abrouter\Client\Builders\Payload;
6+
7+
use Abrouter\Client\DTO\EventDTOInterface;
8+
use Abrouter\Client\Entities\JsonPayload;
9+
10+
class SendEventPayloadBuilder
11+
{
12+
/**
13+
* @param EventDTOInterface $eventDTO
14+
* @return JsonPayload
15+
*/
16+
public function build(EventDTOInterface $eventDTO): JsonPayload
17+
{
18+
return new JsonPayload(
19+
[
20+
'data' => [
21+
'type' => 'events',
22+
'attributes' => [
23+
'event' => $eventDTO->getBaseEventDTO()->getEvent(),
24+
'user_id' => $eventDTO->getBaseEventDTO()->getUserId(),
25+
'temporary_user_id' => $eventDTO->getBaseEventDTO()->getTemporaryUserId(),
26+
'value' => method_exists($eventDTO, 'getValue') ? $eventDTO->getValue() : null,
27+
'tag' => $eventDTO->getBaseEventDTO()->getTag(),
28+
'referrer' => $eventDTO->getBaseEventDTO()->getReferrer(),
29+
'meta' => $eventDTO->getBaseEventDTO()->getMeta(),
30+
'ip' => $eventDTO->getBaseEventDTO()->getIp(),
31+
'created_at' => $eventDTO->getBaseEventDTO()->getCreatedAt()
32+
]
33+
]
34+
]
35+
);
36+
}
37+
}

src/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Client
2020
*/
2121
private StatisticsManager $statisticsManager;
2222

23+
/**
24+
* @var FeatureFlagManager
25+
*/
2326
private FeatureFlagManager $featureFlagManager;
2427

2528
public function __construct(

src/DTO/BaseEventDTO.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Abrouter\Client\DTO;
6+
7+
class BaseEventDTO
8+
{
9+
/**
10+
* @var string|null
11+
*/
12+
private $temporaryUserId;
13+
14+
/**
15+
* @var string|null
16+
*/
17+
private $userId;
18+
19+
/**
20+
* @var string
21+
*/
22+
private $event;
23+
24+
/**
25+
* @var string|null
26+
*/
27+
private ?string $referrer;
28+
29+
/**
30+
* @var string|null
31+
*/
32+
private ?string $tag;
33+
34+
/**
35+
* @var array|null
36+
*/
37+
private ?array $meta;
38+
39+
/**
40+
* @var string|null
41+
*/
42+
private ?string $ip;
43+
44+
/**
45+
* @var string|null
46+
*/
47+
private ?string $created_at;
48+
49+
/**
50+
* BaseEventDTO constructor.
51+
*
52+
* @param string $event
53+
* @param string|null $temporaryUserId
54+
* @param string|null $userId
55+
* @param string|null $tag
56+
* @param string|null $referrer
57+
* @param array|null $meta
58+
* @param string|null $ip
59+
* @param string|null $created_at
60+
*/
61+
public function __construct(
62+
?string $temporaryUserId = null,
63+
?string $userId = null,
64+
string $event,
65+
?string $tag = null,
66+
?string $referrer = null,
67+
?array $meta = null,
68+
?string $ip = null,
69+
?string $created_at = null
70+
) {
71+
$this->temporaryUserId = $temporaryUserId;
72+
$this->userId = $userId;
73+
$this->event = $event;
74+
$this->tag = $tag;
75+
$this->referrer = $referrer;
76+
$this->meta = $meta;
77+
$this->ip = $ip;
78+
$this->created_at = $created_at;
79+
}
80+
81+
/**
82+
* @return string|null
83+
*/
84+
public function getTemporaryUserId(): ?string
85+
{
86+
return $this->temporaryUserId;
87+
}
88+
89+
/**
90+
* @return string|null
91+
*/
92+
public function getUserId(): ?string
93+
{
94+
return $this->userId;
95+
}
96+
97+
/**
98+
* @return string
99+
*/
100+
public function getEvent(): string
101+
{
102+
return $this->event;
103+
}
104+
105+
/**
106+
* @return string|null
107+
*/
108+
public function getReferrer(): ?string
109+
{
110+
return $this->referrer;
111+
}
112+
113+
/**
114+
* @return string|null
115+
*/
116+
public function getTag(): ?string
117+
{
118+
return $this->tag;
119+
}
120+
121+
/**
122+
* @return array|null
123+
*/
124+
public function getMeta(): ?array
125+
{
126+
return $this->meta;
127+
}
128+
129+
/**
130+
* @return string|null
131+
*/
132+
public function getIp(): ?string
133+
{
134+
return $this->ip;
135+
}
136+
137+
/**
138+
* @return string|null
139+
*/
140+
public function getCreatedAt(): ?string
141+
{
142+
return $this->created_at;
143+
}
144+
}

0 commit comments

Comments
 (0)