Skip to content

Commit 71ad2e5

Browse files
committed
codex update
1 parent ea46144 commit 71ad2e5

23 files changed

Lines changed: 836 additions & 63 deletions

src/Analytics.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ class Analytics extends Helper\IOHelper implements Facade\Type\AnalyticsType
1919

2020
protected null|bool $non_personalized_ads = false;
2121
protected null|int $timestamp_micros;
22+
protected null|string $validation_behavior;
23+
protected null|string $ip_override;
2224
protected null|string $client_id;
2325
protected null|string $user_id;
26+
protected array $user_location = [];
27+
protected array $device = [];
2428
protected array $user_properties = [];
2529
protected array $events = [];
2630

@@ -40,8 +44,12 @@ public function getParams(): array
4044
return [
4145
'non_personalized_ads',
4246
'timestamp_micros',
47+
'validation_behavior',
48+
'ip_override',
4349
'client_id',
4450
'user_id',
51+
'user_location',
52+
'device',
4553
'user_properties',
4654
'events',
4755
];
@@ -68,6 +76,12 @@ public function setClientId(string $id)
6876
return $this;
6977
}
7078

79+
public function setNonPersonalizedAds(bool $enabled = true)
80+
{
81+
$this->non_personalized_ads = $enabled;
82+
return $this;
83+
}
84+
7185
public function setUserId(string $id)
7286
{
7387
$this->user_id = $id;
@@ -89,6 +103,30 @@ public function setTimestampMicros(int|float $microOrUnix)
89103
return $this;
90104
}
91105

106+
public function setValidationBehavior(null|string $behavior)
107+
{
108+
$this->validation_behavior = $behavior;
109+
return $this;
110+
}
111+
112+
public function setIpOverride(null|string $ip)
113+
{
114+
$this->ip_override = $ip;
115+
return $this;
116+
}
117+
118+
public function setUserLocation(array $location)
119+
{
120+
$this->user_location = static::cleanAssoc($location);
121+
return $this;
122+
}
123+
124+
public function setDevice(array $device)
125+
{
126+
$this->device = static::cleanAssoc($device);
127+
return $this;
128+
}
129+
92130
public function addUserProperty(Facade\Type\UserPropertyType ...$props)
93131
{
94132
foreach ($props as $prop) {
@@ -130,9 +168,11 @@ public function post(): void
130168
$url = $this->debug ? Facade\Type\AnalyticsType::URL_DEBUG : Facade\Type\AnalyticsType::URL_LIVE;
131169
$url .= '?' . http_build_query(['measurement_id' => $this->measurement_id, 'api_secret' => $this->api_secret]);
132170

171+
$userData = $this->userdata->toArray();
172+
133173
$body = array_replace_recursive(
134174
$this->toArray(),
135-
["user_data" => !empty($this->user_id) ? $this->userdata->toArray() : []], // Only accepted if user_id is passed too
175+
["user_data" => $userData],
136176
["user_properties" => $this->user_properties],
137177
["consent" => $this->consent->toArray()],
138178
);
@@ -197,4 +237,22 @@ public static function new(string $measurement_id, string $api_secret, bool $deb
197237
{
198238
return new static($measurement_id, $api_secret, $debug);
199239
}
240+
241+
private static function cleanAssoc(array $input): array
242+
{
243+
$out = [];
244+
foreach ($input as $key => $value) {
245+
if (!is_string($key)) {
246+
continue;
247+
}
248+
249+
if ($value === null || $value === '') {
250+
continue;
251+
}
252+
253+
$out[$key] = $value;
254+
}
255+
256+
return $out;
257+
}
200258
}

src/Event/EarnVirtualCurrency.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function getParams(): array
2525

2626
public function getRequiredParams(): array
2727
{
28-
return [];
28+
return [
29+
'virtual_currency_name',
30+
'value',
31+
];
2932
}
3033

3134
public function setVirtualCurrencyName(null|string $name)

src/Event/JoinGroup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function getParams(): array
2323

2424
public function getRequiredParams(): array
2525
{
26-
return [];
26+
return [
27+
'group_id',
28+
];
2729
}
2830

2931
public function setGroupId(null|string $id)

src/Event/LevelUp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getParams(): array
2525

2626
public function getRequiredParams(): array
2727
{
28-
return [];
28+
return ['level'];
2929
}
3030

3131
public function setLevel(null|int $lvl)

src/Event/Search.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function getParams(): array
2323

2424
public function getRequiredParams(): array
2525
{
26-
return [];
26+
return [
27+
'search_term',
28+
];
2729
}
2830

2931
public function setSearchTerm(null|string $term)

src/Facade/Type/AnalyticsType.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ interface AnalyticsType extends IOType
1717
*/
1818
public function setClientId(string $id);
1919

20+
/**
21+
* Mark payload as non-personalized ads.
22+
*
23+
* @var non_personalized_ads
24+
* @param bool $enabled
25+
*/
26+
public function setNonPersonalizedAds(bool $enabled = true);
27+
2028
/**
2129
* A unique identifier for a user. See User-ID for cross-platform analysis for more information on this identifier.
2230
*
@@ -34,6 +42,38 @@ public function setUserId(string $id);
3442
*/
3543
public function setTimestampMicros(int|float $microOrUnix);
3644

45+
/**
46+
* Validation behavior for debug endpoint.
47+
*
48+
* @var validation_behavior
49+
* @param string|null $behavior
50+
*/
51+
public function setValidationBehavior(null|string $behavior);
52+
53+
/**
54+
* Override source IP address.
55+
*
56+
* @var ip_override
57+
* @param string|null $ip
58+
*/
59+
public function setIpOverride(null|string $ip);
60+
61+
/**
62+
* Override user location object.
63+
*
64+
* @var user_location
65+
* @param array $location
66+
*/
67+
public function setUserLocation(array $location);
68+
69+
/**
70+
* Override device object.
71+
*
72+
* @var device
73+
* @param array $device
74+
*/
75+
public function setDevice(array $device);
76+
3777
/**
3878
* The user properties for the measurement (Up to 25 custom per project, see link)
3979
*

src/Facade/Type/DefaultEventParamsType.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,61 @@ public function setSessionId(string $id);
6464
*/
6565
public function setEngagementTimeMSec(int $msec);
6666

67+
/**
68+
* Optional event-level override for event timestamp.
69+
*
70+
* @var timestamp_micros
71+
* @param int|float $microOrUnix microtime(true) or time()
72+
*/
73+
public function setEventTimestampMicros(int|float $microOrUnix);
74+
75+
/**
76+
* Campaign source.
77+
*
78+
* @var campaign_source
79+
* @param string $source eg. newsletter
80+
*/
81+
public function setCampaignSource(string $source);
82+
83+
/**
84+
* Campaign medium.
85+
*
86+
* @var campaign_medium
87+
* @param string $medium eg. email
88+
*/
89+
public function setCampaignMedium(string $medium);
90+
91+
/**
92+
* Campaign name.
93+
*
94+
* @var campaign_name
95+
* @param string $name eg. spring_sale
96+
*/
97+
public function setCampaignName(string $name);
98+
99+
/**
100+
* Campaign term.
101+
*
102+
* @var campaign_term
103+
* @param string $term
104+
*/
105+
public function setCampaignTerm(string $term);
106+
107+
/**
108+
* Campaign content.
109+
*
110+
* @var campaign_content
111+
* @param string $content
112+
*/
113+
public function setCampaignContent(string $content);
114+
115+
/**
116+
* Campaign identifier.
117+
*
118+
* @var campaign_id
119+
* @param string $id
120+
*/
121+
public function setCampaignId(string $id);
122+
67123
public function toArray(): array;
68124
}

src/Facade/Type/FirebaseType.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ interface FirebaseType extends IOType
1717
*/
1818
public function setAppInstanceId(string $id);
1919

20+
/**
21+
* Mark payload as non-personalized ads.
22+
*
23+
* @var non_personalized_ads
24+
* @param bool $enabled
25+
*/
26+
public function setNonPersonalizedAds(bool $enabled = true);
27+
2028
/**
2129
* A unique identifier for a user. See User-ID for cross-platform analysis for more information on this identifier.
2230
*
@@ -34,6 +42,38 @@ public function setUserId(string $id);
3442
*/
3543
public function setTimestampMicros(int|float $microOrUnix);
3644

45+
/**
46+
* Validation behavior for debug endpoint.
47+
*
48+
* @var validation_behavior
49+
* @param string|null $behavior
50+
*/
51+
public function setValidationBehavior(null|string $behavior);
52+
53+
/**
54+
* Override source IP address.
55+
*
56+
* @var ip_override
57+
* @param string|null $ip
58+
*/
59+
public function setIpOverride(null|string $ip);
60+
61+
/**
62+
* Override user location object.
63+
*
64+
* @var user_location
65+
* @param array $location
66+
*/
67+
public function setUserLocation(array $location);
68+
69+
/**
70+
* Override device object.
71+
*
72+
* @var device
73+
* @param array $device
74+
*/
75+
public function setDevice(array $device);
76+
3777
/**
3878
* The user properties for the measurement (Up to 25 custom per project, see link)
3979
*

src/Facade/Type/UserPropertyType.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public function setName(string $name): static;
3030
* @return static
3131
*/
3232
public function setValue(int|float|string $value): static;
33+
34+
/**
35+
* Optional timestamp override for when the user property was set.
36+
*
37+
* @param int|float $microOrUnix microtime(true) or time()
38+
* @return static
39+
*/
40+
public function setTimestampMicros(int|float $microOrUnix): static;
3341
}

0 commit comments

Comments
 (0)