You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-15Lines changed: 22 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,25 +73,29 @@ $analytics = Analytics::new(
73
73
74
74
1. Acquire proper GDPR Consent
75
75
2. Client/GTAG.js sends session_start and first_visit to GA4
76
-
3. GA4 sends \_ga and \_gid cookies back to Client/GTAG.js
77
-
4. Server uses \_ga (or \_gid; or your unique session_id) to populate events
76
+
3. GA4 sends `_ga` and `_gid` cookies back to Client/GTAG.js
77
+
4. Server uses `_ga` (or `_gid`; or your unique session_id) to populate events
78
78
79
79
Note: It is entirely possible to push events to backend without acquiring the session cookies from Google Analytics; you will however lose information bundled inside the `GTAG.js` request if you do not figure out how to push that via backend too.
80
80
81
81
### Layers
82
82
83
-
The code is following 3 layers, that should be considered.
83
+
The code is following 3 layers that should be considered; 5 layers at max.
84
84
85
85
```txt
86
86
Analytics [
87
-
Event [
88
-
Event Parameters
89
-
? Items [
90
-
Item Parameters
91
-
]
87
+
Events [
88
+
Event {
89
+
Parameters
90
+
? Items [
91
+
Item Parameters
92
+
]
93
+
}
92
94
]
93
95
User Properties [
94
-
Properties {Key, Value} pairs
96
+
Properties {
97
+
Key: Value
98
+
}
95
99
]
96
100
]
97
101
```
@@ -259,7 +263,8 @@ try {
259
263
260
264
## Custom Events
261
265
262
-
You can build your own custom events. All you need is to implement and fullfill the `AlexWestergaard\PhpGa4\Facade\Type\EventType` facade/interface. If you want ease of life features, then you can extend your event from `AlexWestergaard\PhpGa4\Helper\EventHelper` and overwrite as you see fit.
266
+
You can build your own custom events. All you need is to implement and fullfill the `AlexWestergaard\PhpGa4\Facade\Type\EventType` facade/interface.
267
+
If you want ease of life features, then you can extend your event from `AlexWestergaard\PhpGa4\Helper\EventHelper` and overwrite as you see fit.
263
268
264
269
```php
265
270
@@ -309,17 +314,19 @@ class ExampleEvent extends AlexWestergaard\PhpGa4\Helper\EventHelper
309
314
310
315
## Debug
311
316
312
-
Measurement protocol for GA4 has a debug functionality that can be enabled with the `debug` parameter in the constructor.
317
+
Measurement protocol for GA4 has debug functionality that can be enabled with the `debug` parameter in the Analytics constructor.
313
318
314
319
```php
315
320
$analytics = Analytics::new(
316
321
measurement_id: 'G-XXXXXXXX',
317
322
api_secret: 'xYzzX_xYzzXzxyZxX',
318
-
debug: true
323
+
debug: true // default: false
319
324
);
320
325
```
321
326
322
-
Once set, events are sent to `https://www.google-analytics.com/debug/mp/collect` which will return a validation response such as
327
+
When `Debug` is enabled then events are sent to `https://www.google-analytics.com/debug/mp/collect` where issues will be caught with
328
+
[GA4Exception](https://github.com/aawnu/php-ga4/blob/master/src/Exception/Ga4Exception.php) (Be aware of `$exception->getPrevious()` stacks);
329
+
such response will look as follows:
323
330
324
331
```json
325
332
{
@@ -333,12 +340,12 @@ Once set, events are sent to `https://www.google-analytics.com/debug/mp/collect`
333
340
}
334
341
```
335
342
336
-
This library already validates that events are properly formatted and it is unlikely, you will experience any validation messages.
343
+
Notice: This library already validates that events are properly formatted when added to analytics (`$analytics->addEvent(...)`).
337
344
338
345
Two important points:
339
346
340
347
- Events sent to the Validation Server will not show up in reports.
341
-
- There is no way for events sent through measurement protocol to show up in the `debugView` in Google Analytics Admin.
348
+
- There is no way for events sent through measurement protocol (Server Side) to show up in the `debugView` in Google Analytics Admin.
0 commit comments