@@ -81,56 +81,48 @@ Analytics [
8181
8282This is a list of prebuilt events as shown in the documentation. All events have the following parameters to locate trigger location of each event.
8383
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-
9684### Default
9785
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 )
11098
11199### E-commerce
112100
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 )
123111
124112### Engagement / Gaming
125113
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 )
134126
135127## Frontend & Backend Communication
136128
@@ -147,54 +139,69 @@ use AlexWestergaard\PhpGa4\Analytics;
147139use AlexWestergaard\PhpGa4\Event;
148140use AlexWestergaard\PhpGa4\Item;
149141
150- $visitors = getVisitorsAndEvents(); // pseudo function, make your own logic here
142+ // pseudo function, make your own logic here
143+ $visitors = getVisitorsWithEvents();
151144
152- foreach ($visitors as $collection ) {
145+ foreach ($visitors as $visitor ) {
153146 // Group of events, perhaps need logic to change from json or array to event objects
154147 // Maybe its formatted well for the > ConvertHelper::parseEvents([...]) < helper
155- $groups = $collection ['events'];
148+ $groups = $visitor ['events'];
156149
157150 // If gtag.js, this can be the _ga or _gid cookie
158151 // This can be any kind of session identifier
159152 // Usually derives from $_COOKIE['_ga'] or $_COOKIE['_gid'] set by GTAG.js
160- $visitor = $collection['session_id '];
153+ $client = $visitor['client_id '];
161154
162155 // load logged in user/visitor
163156 // This can be any kind of unique identifier, readable is easier for you
164157 // Just be wary not to use GDPR sensitive information
165- $user = $collection['user_id'];
158+ $user = $visitor['user_id'];
159+ $userParameters = $visitor["user_parameters"]
166160
167161 // Render events grouped on time (max offset is 3 days from NOW)
168162 foreach ($groups as $time => $data) {
169163 try {
170164 $analytics = Analytics::new($measurementId, $apiSecret)
171- ->setClientId($visitor )
165+ ->setClientId($client )
172166 ->setTimestampMicros($time);
173167
174168 if ($user !== null) {
175169 $analytics->setUserId($user);
176170 }
177171
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']);
180176
181- $analytics->post(); // send events to Google Analytics
177+ // send events to Google Analytics
178+ $analytics->post();
182179 } catch (Exception\Ga4Exception $exception) {
183180 // Handle exception
184181 // Exceptions might be stacked, check: $exception->getPrevious();
182+ ExceptionTrail(function(Exception $e) {/*...*/}, $exception)
185183 }
186184 }
187185}
188186
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+
189197```
190198
191199## Custom Events
192200
193201You 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.
195203
196204``` php
197-
198205// EventHelper implements AlexWestergaard\PhpGa4\Facade\Type\EventType
199206class ExampleEvent extends AlexWestergaard\PhpGa4\Helper\EventHelper
200207{
0 commit comments