@@ -81,56 +81,48 @@ Analytics [
81
81
82
82
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.
83
83
84
- ``` php
85
- // Manual setting of each event
86
- $event->setLanguage(string $var);
87
- $event->setPageLocation(string $var);
88
- $event->setPageReferrer(string $var);
89
- $event->setPageTitle(string $var);
90
- $event->setScreenResolution(string $var);
91
- // Fillable for multiple events
92
- $eventPage = AlexWestergaard\PhpGa4\Helper\EventParamsHelper(...);
93
- $event->setEventPage($eventPage);
94
- ```
95
-
96
84
### Default
97
85
98
- ![ badge ] ( https://shields.io/badge/ PageView-informational )
99
- ![ badge ] ( https://shields.io/badge/ Share-informational )
100
- ![ badge ] ( https://shields.io/badge/ Signup-informational )
101
- ![ badge ] ( https://shields.io/badge/ Login-informational )
102
- ![ badge ] ( https://shields.io/badge/ Search-informational )
103
- ![ badge ] ( https://shields.io/badge/ SelectContent-informational )
104
- ![ badge ] ( https://shields.io/badge/ SelectItem-informational )
105
- ![ badge ] ( https://shields.io/badge/ SelectPromotion-informational )
106
- ![ badge ] ( https://shields.io/badge/ ViewItem-informational )
107
- ![ badge ] ( https://shields.io/badge/ ViewItemList-informational )
108
- ![ badge ] ( https://shields.io/badge/ ViewPromotion-informational )
109
- ![ badge ] ( https://shields.io/badge/ ViewSearchResults-informational )
86
+ - [ PageView ] ( src/Event/ PageView.php )
87
+ - [ Share ] ( src/Event/ Share.php )
88
+ - [ Signup ] ( src/Event/ Signup.php )
89
+ - [ Login ] ( src/Event/ Login.php )
90
+ - [ Search ] ( src/Event/ Search.php )
91
+ - [ SelectContent ] ( src/Event/ SelectContent.php )
92
+ - [ SelectItem ] ( src/Event/ SelectItem.php )
93
+ - [ SelectPromotion ] ( src/Event/ SelectPromotion.php )
94
+ - [ ViewItem ] ( src/Event/ ViewItem.php )
95
+ - [ ViewItemList ] ( src/Event/ ViewItemList.php )
96
+ - [ ViewPromotion ] ( src/Event/ ViewPromotion.php )
97
+ - [ ViewSearchResults ] ( src/Event/ ViewSearchResults.php )
110
98
111
99
### E-commerce
112
100
113
- ![ badge ] ( https://shields.io/badge/ GenerateLead-informational )
114
- ![ badge ] ( https://shields.io/badge/ AddToWishlist-informational )
115
- ![ badge ] ( https://shields.io/badge/ AddToCart-informational )
116
- ![ badge ] ( https://shields.io/badge/ ViewCart-informational )
117
- ![ badge ] ( https://shields.io/badge/ RemoveFromCart-informational )
118
- ![ badge ] ( https://shields.io/badge/ BeginCheckout-informational )
119
- ![ badge ] ( https://shields.io/badge/ AddPaymentInfo-informational )
120
- ![ badge ] ( https://shields.io/badge/ AddShippingInfo-informational )
121
- ![ badge ] ( https://shields.io/badge/ Purchase-informational )
122
- ![ badge ] ( https://shields.io/badge/ Refund-informational )
101
+ - [ GenerateLead ] ( src/Event/ GenerateLead.php )
102
+ - [ AddToWishlist ] ( src/Event/ AddToWishlist.php )
103
+ - [ AddToCart ] ( src/Event/ AddToCart.php )
104
+ - [ ViewCart ] ( src/Event/ ViewCart.php )
105
+ - [ RemoveFromCart ] ( src/Event/ RemoveFromCart.php )
106
+ - [ BeginCheckout ] ( src/Event/ BeginCheckout.php )
107
+ - [ AddPaymentInfo ] ( src/Event/ AddPaymentInfo.php )
108
+ - [ AddShippingInfo ] ( src/Event/ AddShippingInfo.php )
109
+ - [ Purchase ] ( src/Event/ Purchase.php )
110
+ - [ Refund ] ( src/Event/ Refund.php )
123
111
124
112
### Engagement / Gaming
125
113
126
- ![ badge] ( https://shields.io/badge/EarnVirtualCurrency-informational )
127
- ![ badge] ( https://shields.io/badge/SpendVirtualCurrency-informational )
128
- ![ badge] ( https://shields.io/badge/LevelUp-informational )
129
- ![ badge] ( https://shields.io/badge/PostScore-informational )
130
- ![ badge] ( https://shields.io/badge/TutorialBegin-informational )
131
- ![ badge] ( https://shields.io/badge/TutorialComplete-informational )
132
- ![ badge] ( https://shields.io/badge/UnlockAchievement-informational )
133
- ![ badge] ( https://shields.io/badge/JoinGroup-informational )
114
+ - [ EarnVirtualCurrency] ( src/Event/EarnVirtualCurrency.php )
115
+ - [ SpendVirtualCurrency] ( src/Event/SpendVirtualCurrency.php )
116
+ - [ LevelUp] ( src/Event/LevelUp.php )
117
+ - [ PostScore] ( src/Event/PostScore.php )
118
+ - [ TutorialBegin] ( src/Event/TutorialBegin.php )
119
+ - [ TutorialComplete] ( src/Event/TutorialComplete.php )
120
+ - [ UnlockAchievement] ( src/Event/UnlockAchievement.php )
121
+ - [ JoinGroup] ( src/Event/JoinGroup.php )
122
+
123
+ ### Reporting
124
+
125
+ - [ Exception] ( src/Event/Exception.php )
134
126
135
127
## Frontend & Backend Communication
136
128
@@ -147,54 +139,69 @@ use AlexWestergaard\PhpGa4\Analytics;
147
139
use AlexWestergaard\PhpGa4\Event;
148
140
use AlexWestergaard\PhpGa4\Item;
149
141
150
- $visitors = getVisitorsAndEvents(); // pseudo function, make your own logic here
142
+ // pseudo function, make your own logic here
143
+ $visitors = getVisitorsWithEvents();
151
144
152
- foreach ($visitors as $collection ) {
145
+ foreach ($visitors as $visitor ) {
153
146
// Group of events, perhaps need logic to change from json or array to event objects
154
147
// Maybe its formatted well for the > ConvertHelper::parseEvents([...]) < helper
155
- $groups = $collection ['events'];
148
+ $groups = $visitor ['events'];
156
149
157
150
// If gtag.js, this can be the _ga or _gid cookie
158
151
// This can be any kind of session identifier
159
152
// Usually derives from $_COOKIE['_ga'] or $_COOKIE['_gid'] set by GTAG.js
160
- $visitor = $collection['session_id '];
153
+ $client = $visitor['client_id '];
161
154
162
155
// load logged in user/visitor
163
156
// This can be any kind of unique identifier, readable is easier for you
164
157
// Just be wary not to use GDPR sensitive information
165
- $user = $collection['user_id'];
158
+ $user = $visitor['user_id'];
159
+ $userParameters = $visitor["user_parameters"]
166
160
167
161
// Render events grouped on time (max offset is 3 days from NOW)
168
162
foreach ($groups as $time => $data) {
169
163
try {
170
164
$analytics = Analytics::new($measurementId, $apiSecret)
171
- ->setClientId($visitor )
165
+ ->setClientId($client )
172
166
->setTimestampMicros($time);
173
167
174
168
if ($user !== null) {
175
169
$analytics->setUserId($user);
176
170
}
177
171
178
- $analytics->addUserParameter(...$data['userParameters']); // pseudo logic for adding user parameters
179
- $analytics->addEvent(...$data['events']); // pseudo logic for adding events
172
+ // pseudo logic for adding user parameters
173
+ $analytics->addUserParameter(...$userParameters);
174
+ // pseudo logic for adding events
175
+ $analytics->addEvent(...$data['events']);
180
176
181
- $analytics->post(); // send events to Google Analytics
177
+ // send events to Google Analytics
178
+ $analytics->post();
182
179
} catch (Exception\Ga4Exception $exception) {
183
180
// Handle exception
184
181
// Exceptions might be stacked, check: $exception->getPrevious();
182
+ ExceptionTrail(function(Exception $e) {/*...*/}, $exception)
185
183
}
186
184
}
187
185
}
188
186
187
+ // pseudo function to trail the exception tree
188
+ function ExceptionTrail(callable $handler, Exception $e) {
189
+ $handler($e);
190
+
191
+ $prev = $e->getPrevious();
192
+ if ($prev instanceof Exception) {
193
+ ExceptionTrail($handler, $prev);
194
+ }
195
+ }
196
+
189
197
```
190
198
191
199
## Custom Events
192
200
193
201
You can build your own custom events. All you need is to implement and fullfill the ` AlexWestergaard\PhpGa4\Facade\Type\EventType ` facade/interface.
194
- If you want ease of life features, then you can extend your event from ` AlexWestergaard\PhpGa4\Helper\EventHelper ` and overwrite as you see fit.
202
+ If you want quality of life features, then you can extend your event from ` AlexWestergaard\PhpGa4\Helper\EventHelper ` or ` AlexWestergaard\PhpGa4\Helper\EventMainHelper ` and overwrite as you see fit.
195
203
196
204
``` php
197
-
198
205
// EventHelper implements AlexWestergaard\PhpGa4\Facade\Type\EventType
199
206
class ExampleEvent extends AlexWestergaard\PhpGa4\Helper\EventHelper
200
207
{
0 commit comments