Skip to content

Commit 2e5f201

Browse files
committed
fix: add UserData to Analytics.php with Resetter
1 parent 16fdae6 commit 2e5f201

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Analytics.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ public function post(): void
132132

133133
$body = array_replace_recursive(
134134
$this->toArray(),
135+
["user_data" => $this->user_id != null ? $this->userdata->toArray() : []], // Only accepted if user_id is passed too
135136
["user_properties" => $this->user_properties],
136137
["consent" => $this->consent->toArray()],
137138
);
138139

140+
if (count($body["user_data"]) < 1) unset($body["user_data"]);
141+
if (count($body["user_properties"]) < 1) unset($body["user_properties"]);
142+
139143
$chunkEvents = array_chunk($this->events, 25);
140144

141145
if (count($chunkEvents) < 1) {
142146
throw Ga4Exception::throwMissingEvents();
143147
}
144148

149+
$this->userdata->reset();
145150
$this->user_properties = [];
146151
$this->events = [];
147152

src/Helper/UserDataHelper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ class UserDataHelper
1515
private ?string $postal_code = null;
1616
private ?string $country = null;
1717

18+
public function reset(): void
19+
{
20+
$this->sha256_email_address = null;
21+
$this->sha256_phone_number = null;
22+
$this->sha256_first_name = null;
23+
$this->sha256_last_name = null;
24+
$this->sha256_street = null;
25+
$this->city = null;
26+
$this->region = null;
27+
$this->postal_code = null;
28+
$this->country = null;
29+
}
30+
1831
/**
1932
* @param string $email
2033
* @return bool

0 commit comments

Comments
 (0)