Skip to content

Commit 9d30dde

Browse files
committed
docs: update readme
1 parent a211240 commit 9d30dde

File tree

1 file changed

+23
-45
lines changed

1 file changed

+23
-45
lines changed

README.md

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
_Package_
2-
31
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=blue&label=stable%20release)](https://github.com/aawnu/php-ga4/releases/latest)
4-
[![License](https://img.shields.io/packagist/l/alexwestergaard/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/blob/master/LICENSE)
5-
[![PHPVersion](https://img.shields.io/packagist/php-v/alexwestergaard/php-ga4?color=blue)](https://www.php.net/releases)
6-
[![Size](https://img.shields.io/github/languages/code-size/aawnu/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/releases/latest)
2+
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=yellow&include_prereleases&label=latest%20release)](https://github.com/aawnu/php-ga4/releases)
73
![Code Coverage Badge](https://raw.githubusercontent.com/AlexWestergaard/php-ga4/image-data/coverage.svg)
8-
9-
_Development_
10-
11-
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=red&include_prereleases&label=latest%20release)](https://github.com/aawnu/php-ga4/releases)
4+
[![PHPVersion](https://img.shields.io/packagist/php-v/alexwestergaard/php-ga4?color=blue)](https://www.php.net/releases)
5+
[![Size](https://img.shields.io/github/languages/code-size/aawnu/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/releases/latest) [![Contributors](https://img.shields.io/github/contributors/aawnu/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/graphs/contributors)
126
[![Issues](https://img.shields.io/github/issues-raw/alexwestergaard/php-ga4?color=red&label=issues)](https://github.com/aawnu/php-ga4/issues)
137
[![Pulls](https://img.shields.io/github/issues-pr/aawnu/php-ga4?color=red&label=pulls)](https://github.com/aawnu/php-ga4/pulls)
14-
[![Contributors](https://img.shields.io/github/contributors/aawnu/php-ga4?color=red)](https://github.com/aawnu/php-ga4/graphs/contributors)
158
[![LastCommit](https://img.shields.io/github/last-commit/aawnu/php-ga4/master?color=red)](https://github.com/aawnu/php-ga4/commits)
169

1710
```sh
@@ -36,66 +29,45 @@ composer require alexwestergaard/php-ga4
3629
- [Additional information](#additional-information)
3730
- [Documentation](#documentation)
3831

39-
## GDPR Notice
40-
41-
European Union have noticed that default setup of Google Analytics does not comply with GDPR as data is sent unrestricted to an american service possibly outside of Europe.
42-
This includes the use of `gtag.js` as JavaScript pushes the request from visitors device including their IP-Address.
43-
44-
Server Side Tracking, however, does only send information specified inside the body and about your server.
32+
## Europe - GDPR Notice
4533

46-
Relying solely on Google Analytics 4 Events - that is not pushed through the `gtag.js` script - can be scraped of GDPR-related information.
34+
The European Union have notified that Google Analytics does not comply with GDPR by default. This is because the frontend Client sends visitor details like their IP Address and device information with events. This can be avoided with a middle-man server inside the European Region.
4735

4836
- Source: Europe, GDPR, Schrems II
49-
- https://support.google.com/analytics/answer/9019185?hl=en
37+
- Options: [Privacy controls in Google Analytics](https://support.google.com/analytics/answer/9019185?hl=en)
5038

5139
## Getting started
5240

53-
To setup Analytics you need a Measurement ID and API Secret.
41+
Setup requires a **Measurement ID** and **API Secret**. Go to Administrator (Bottom left) -> Account -> Data Streams -> {Your Stream}. Here you should find Measurement ID at top and "Api Secrets for Measurement Protocol" a little down the page, where you can create yourself an `API secret`.
5442

5543
Go to `Administrator` (bottom left) and then select your `Account` -> `Data Streams` -> your stream.
5644
Here you will find `Measurement-ID` at top from and further down `Api Secrets for Measurement Protocol`, in there you can create yourself an `API Secret`.
5745

58-
**PLEASE** note that Google Analytics will look out from traffic gathered by the `gtag.js` library, as Server Side Events are supposed to supplement the frontend through its `_ga`/`_gid` cookie sessions.
46+
Once you have obtained the credentials, you can initialise the Analytics like this:
5947

6048
```php
6149
use AlexWestergaard\PhpGa4\Analytics;
6250

6351
$analytics = Analytics::new(
6452
measurement_id: 'G-XXXXXXXX',
6553
api_secret: 'xYzzX_xYzzXzxyZxX',
66-
debug: true|false
54+
debug: true|false #Default: False
6755
);
68-
69-
// You can set CONSENT here if not done through the gtat.js
70-
// Read full docs here: https://support.google.com/tagmanager/answer/13802165
71-
$consent = $analytics->consent(); // returns a consent handler
72-
73-
// Sets consent for sending user data from the request's events
74-
// and user properties to Google for advertising purposes.
75-
$consent->setAdUserDataPermission();
76-
$consent->getAdUserDataPermission();
77-
$consent->clearAdUserDataPermission();
78-
79-
// Sets consent for personalized advertising for the user.
80-
$consent->setAdPersonalizationPermission();
81-
$consent->getAdPersonalizationPermission();
82-
$consent->clearAdPersonalizationPermission();
8356
```
8457

8558
### Data flow
8659

87-
`session_id` > Google Analytics does not specify a required type of **session or user id**. You are free to use any kind of **unique identifier** you want; the catch, however, is that Google Analytics populates some internal data with `gtag.js`, that is then referenced to their `_ga` cookie session id. Just be aware that `gtag.js` is using _client-side Javascript_ and can therefore have some **GDPR complications** as requests back to Google Analytics contains client information; such as their IP Address.
60+
Server Side Tagging is not supposed to replace the frontend Client and session initiation should happen through the `gtag.js` Client. The default flow is supposed to happen as follows:
8861

89-
1. Acquire proper GDPR Consent
90-
2. Client/GTAG.js sends session_start and first_visit to GA4
91-
3. GA4 sends `_ga` and `_gid` cookies back to Client/GTAG.js
92-
4. Server uses `_ga` (or `_gid`; or your unique session_id) to populate events
62+
1. Obtain proper GDPR Consent
63+
2. Client/GTAG.js initiates session with Google Analytics
64+
3. Google Analytics sends `_ga` and `_gid` cookies back to Client/GTAG.js
65+
4. Server uses `_ga` (or `_gid`) to send/populate events
66+
- Eg. GenerateLead, Purchase, Refund and other backend handled events.
9367

94-
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.
68+
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. You can replace the `_ga` and `_gid` sessions with your own uniquely generated id.
9569

96-
### Layers
97-
98-
The code is following 3 layers that should be considered; 5 layers at max.
70+
All requests should follow this structure and contain at least 1 event for Google Analytics to accept it.
9971

10072
```txt
10173
Analytics [
@@ -112,6 +84,12 @@ Analytics [
11284
Key: Value
11385
}
11486
]
87+
? Consent {
88+
Key: Value
89+
}
90+
? User Data {
91+
Key: Value
92+
}
11593
]
11694
```
11795

0 commit comments

Comments
 (0)