Skip to content

Commit 0ddfd87

Browse files
author
Alex Westergaard
committed
Update README for latest changes
1 parent a3e997e commit 0ddfd87

File tree

1 file changed

+60
-28
lines changed

1 file changed

+60
-28
lines changed

README.md

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
_Package_
22

3-
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=blue&label=stable)](https://github.com/aawnu/php-ga4/releases/latest)
3+
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=blue&label=stable%20release)](https://github.com/aawnu/php-ga4/releases/latest)
44
[![License](https://img.shields.io/packagist/l/alexwestergaard/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/blob/master/LICENSE)
55
[![PHPVersion](https://img.shields.io/packagist/php-v/alexwestergaard/php-ga4?color=blue)](https://www.php.net/releases)
66
[![Size](https://img.shields.io/github/languages/code-size/aawnu/php-ga4?color=blue)](https://github.com/aawnu/php-ga4/releases/latest)
77
![Code Coverage Badge](https://raw.githubusercontent.com/AlexWestergaard/php-ga4/image-data/coverage.svg)
88

99
_Development_
1010

11-
[![Version](https://img.shields.io/packagist/v/alexwestergaard/php-ga4?color=red&include_prereleases&label=latest)](https://github.com/aawnu/php-ga4/releases)
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)
1212
[![Issues](https://img.shields.io/github/issues-raw/alexwestergaard/php-ga4?color=red&label=issues)](https://github.com/aawnu/php-ga4/issues)
1313
[![Pulls](https://img.shields.io/github/issues-pr/aawnu/php-ga4?color=red&label=pulls)](https://github.com/aawnu/php-ga4/pulls)
1414
[![Contributors](https://img.shields.io/github/contributors/aawnu/php-ga4?color=red)](https://github.com/aawnu/php-ga4/graphs/contributors)
@@ -34,34 +34,60 @@ composer require alexwestergaard/php-ga4
3434

3535
## GDPR Notice
3636

37-
> 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.
38-
>
39-
> This includes the use of `gtag.js`/`gtm.js` as JavaScript pushes the request from visitors device including their IP-Address. Server Side Tracking, however, does only send information specified inside the body and about your server.
40-
>
41-
> Relying solely on Google Analytics 4 Events - that is not pushed through the `gtag.js`/`gtm.js` script - can be scraped of GDPR-related information.
37+
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.
38+
This includes the use of `gtag.js` as JavaScript pushes the request from visitors device including their IP-Address.
39+
40+
Server Side Tracking, however, does only send information specified inside the body and about your server.
41+
42+
Relying solely on Google Analytics 4 Events - that is not pushed through the `gtag.js` script - can be scraped of GDPR-related information.
4243

4344
- Source: Europe, GDPR, Schrems II
4445
- https://support.google.com/analytics/answer/9019185?hl=en
4546

4647
## Getting started
4748

48-
To get started, you will need two things:
49+
To setup Analytics you need a Measurement ID and API Secret.
50+
51+
Go to `Administrator` (bottom left) and then select your `Account` -> `Data Streams` -> your stream.
52+
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`.
4953

50-
- a data stream can be created under `Admin` > `Data Streams`, get its measurement id eg. `G-XXXXXXXX`
51-
- an API key to send events to the data stream `Admin` > `Data Streams` > Select data stream > `Measurement Protocol API secrets` > `Create`
54+
**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.
5255

5356
```php
5457
use AlexWestergaard\PhpGa4\Analytics;
5558

56-
$analytics = Analytics::new('G-XXXXXXXX', 'xYzzX_xYzzXzxyZxX');
59+
$analytics = Analytics::new(
60+
measurement_id: 'G-XXXXXXXX',
61+
api_secret: 'xYzzX_xYzzXzxyZxX',
62+
debug: true/false
63+
);
5764
```
5865

5966
## Events
6067

61-
This is a list of prebuilt events as shown in the documentation.
68+
This is a list of prebuilt events as shown in the documentation. All events have the following parameters to locate trigger location of each event or if they were related to any campaigns/referrals.
69+
70+
```php
71+
// Manual setting of each event
72+
$event->setLanguage(string $var);
73+
$event->setPageLocation(string $var);
74+
$event->setPageReferrer(string $var);
75+
$event->setPageTitle(string $var);
76+
$event->setScreenResolution(string $var);
77+
// Fillable for multiple events
78+
$eventPage = AlexWestergaard\PhpGa4\Helper\EventParamsHelper();
79+
$event->setEventPage($eventPage);
80+
```
81+
82+
```php
83+
// Campaign parameters (Experimental)
84+
$campaign = AlexWestergaard\PhpGa4\Campaign()
85+
$event->setCampaign($campaign);
86+
```
6287

6388
### Default
6489

90+
![badge](https://shields.io/badge/PageView-informational)
6591
![badge](https://shields.io/badge/Share-informational)
6692
![badge](https://shields.io/badge/Signup-informational)
6793
![badge](https://shields.io/badge/Login-informational)
@@ -147,22 +173,28 @@ foreach ($groups as $time => $data) {
147173
#### Frontend
148174

149175
```js
150-
axios.post('/api/ga4', [
151-
{
152-
addToCart: {
153-
currency: 'EUR',
154-
value: 13.37,
155-
items: [
156-
{
157-
'item_id': 1,
158-
'item_name': 'Cup',
159-
'price': 13.37,
160-
'quantity': 1
161-
}
162-
]
176+
// array<array<eventName,eventParams>>
177+
axios.post(
178+
'/api/ga4',
179+
[
180+
// Note each event is its own object inside an array as
181+
// this allows to pass the same event type multiple times
182+
{
183+
addToCart: {
184+
currency: 'EUR',
185+
value: 13.37,
186+
items: [
187+
{
188+
'item_id': 1,
189+
'item_name': 'Cup',
190+
'price': 13.37,
191+
'quantity': 1
192+
}
193+
]
194+
}
163195
}
164-
}
165-
])
196+
]
197+
)
166198
```
167199

168200
#### Backend
@@ -189,7 +221,7 @@ try {
189221

190222
## Custom Events
191223

192-
You can build your own custom events. All you need is to implement and fullfill the `AlexWestergaard\PhpGa4\Facade\Type\Event` facade/interface. If you want ease of life features, then you can extend your event from `AlexWestergaard\PhpGa4\Helper\AbstractEvent` and overwrite as you see fit.
224+
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.
193225

194226
```php
195227

0 commit comments

Comments
 (0)