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
GA has an endpoint that you can hit to register multiple hits at once, with a limit of 20 hits. Hits to be send can be placed in a queue as you build up the Analytics object.
203
+
204
+
Here's an example that sends two hits, and then empties the queue.
205
+
206
+
```php
207
+
$analytics = new Analytics(false, false);
208
+
209
+
$analytics
210
+
->setProtocolVersion('1')
211
+
->setTrackingId('UA-xxxxxx-x')
212
+
->setClientId('xxxxxx.xxxxxx');
213
+
214
+
foreach(range(0, 19) as $i) {
215
+
$analytics = $analytics
216
+
->setDocumentPath("/mypage$i")
217
+
->enqueuePageview(); //enqueue url without pushing
218
+
}
219
+
220
+
$analytics->sendEnqueuedHits(); //push 20 pageviews in a single request and empties the queue
221
+
```
222
+
223
+
The queue is emptied when the hits are sent, but it can also be empty manually with `emptyQueue` method.
224
+
225
+
```php
226
+
$analytics = new Analytics(false, false);
227
+
228
+
$analytics
229
+
->setProtocolVersion('1')
230
+
->setTrackingId('UA-xxxxxx-x')
231
+
->setClientId('xxxxxx.xxxxxx');
232
+
233
+
foreach(range(0, 5) as $i) {
234
+
$analytics = $analytics
235
+
->setDocumentPath("/mypage$i")
236
+
->enqueuePageview(); //enqueue url without pushing
237
+
}
238
+
239
+
$analytics->emptyQueue(); // empty queue, allows to enqueue 20 hits again
240
+
241
+
foreach(range(1, 20) as $i) {
242
+
$analytics = $analytics
243
+
->setDocumentPath("/mypage$i")
244
+
->enqueuePageview(); //enqueue url without pushing
245
+
}
246
+
247
+
$analytics->sendEnqueuedHits(); //push 20 pageviews in a single request and empties the queue
248
+
```
249
+
250
+
If more than 20 hits are attempted to be enqueue, the library will throw a `EnqueueUrlsOverflowException`.
0 commit comments