@@ -17,11 +17,14 @@ class LaravelMatomoTracker extends MatomoTracker
17
17
protected $ tokenAuth ;
18
18
/** @var string */
19
19
protected $ queue ;
20
+ /** @var string */
21
+ protected $ queueConnection ;
20
22
21
23
public function __construct (?Request $ request , ?int $ idSite = null , ?string $ apiUrl = null , ?string $ tokenAuth = null )
22
24
{
23
25
$ this ->tokenAuth = $ tokenAuth ?: config ('matomotracker.tokenAuth ' );
24
26
$ this ->queue = config ('matomotracker.queue ' , 'matomotracker ' );
27
+ $ this ->queueConnection = config ('matomotracker.queueConnection ' , 'default ' );
25
28
26
29
$ this ->setTokenAuth (!is_null ($ tokenAuth ) ? $ tokenAuth : config ('matomotracker.tokenAuth ' ));
27
30
$ this ->setMatomoVariables ($ request , $ idSite , $ apiUrl );
@@ -45,7 +48,8 @@ private function setMatomoVariables(Request $request, int $idSite = null, string
45
48
$ this ->ecommerceItems = array ();
46
49
$ this ->attributionInfo = false ;
47
50
$ this ->eventCustomVar = false ;
48
- $ this ->forcedDatetime = false ;
51
+ // force-set time, so queued commands use the right request time
52
+ $ this ->forcedDatetime = time ();
49
53
$ this ->forcedNewVisit = false ;
50
54
$ this ->networkTime = false ;
51
55
$ this ->serverTime = false ;
@@ -302,6 +306,7 @@ public function queuePageView(string $documentTitle)
302
306
dispatch (function () use ($ documentTitle ) {
303
307
$ this ->doTrackPageView ($ documentTitle );
304
308
})
309
+ ->onConnection ($ this ->queueConnection )
305
310
->onQueue ($ this ->queue );
306
311
}
307
312
@@ -319,6 +324,7 @@ public function queueEvent(string $category, string $action, $name = false, $val
319
324
dispatch (function () use ($ category , $ action , $ name , $ value ) {
320
325
$ this ->doTrackEvent ($ category , $ action , $ name , $ value );
321
326
})
327
+ ->onConnection ($ this ->queueConnection )
322
328
->onQueue ($ this ->queue );
323
329
}
324
330
@@ -335,6 +341,7 @@ public function queueContentImpression(string $contentName, string $contentPiece
335
341
dispatch (function () use ($ contentName , $ contentPiece , $ contentTarget ) {
336
342
$ this ->doTrackContentImpression ($ contentName , $ contentPiece , $ contentTarget );
337
343
})
344
+ ->onConnection ($ this ->queueConnection )
338
345
->onQueue ($ this ->queue );
339
346
}
340
347
@@ -352,6 +359,7 @@ public function queueContentInteraction(string $interaction, string $contentName
352
359
dispatch (function () use ($ interaction , $ contentName , $ contentPiece , $ contentTarget ) {
353
360
$ this ->doTrackContentInteraction ($ interaction , $ contentName , $ contentPiece , $ contentTarget );
354
361
})
362
+ ->onConnection ($ this ->queueConnection )
355
363
->onQueue ($ this ->queue );
356
364
}
357
365
@@ -368,6 +376,7 @@ public function queueSiteSearch(string $keyword, string $category = '', $countR
368
376
dispatch (function () use ($ keyword , $ category , $ countResults ) {
369
377
$ this ->doTrackSiteSearch ($ keyword , $ category , $ countResults );
370
378
})
379
+ ->onConnection ($ this ->queueConnection )
371
380
->onQueue ($ this ->queue );
372
381
}
373
382
@@ -383,6 +392,7 @@ public function queueGoal($idGoal, $revencue = 0.0)
383
392
dispatch (function () use ($ idGoal , $ revencue ) {
384
393
$ this ->doTrackGoal ($ idGoal , $ revencue );
385
394
})
395
+ ->onConnection ($ this ->queueConnection )
386
396
->onQueue ($ this ->queue );
387
397
}
388
398
@@ -397,6 +407,7 @@ public function queueDownload(string $actionUrl)
397
407
dispatch (function () use ($ actionUrl ) {
398
408
$ this ->doTrackDownload ($ actionUrl );
399
409
})
410
+ ->onConnection ($ this ->queueConnection )
400
411
->onQueue ($ this ->queue );
401
412
}
402
413
@@ -411,6 +422,7 @@ public function queueOutlink(string $actionUrl)
411
422
dispatch (function () use ($ actionUrl ) {
412
423
$ this ->doTrackOutlink ($ actionUrl );
413
424
})
425
+ ->onConnection ($ this ->queueConnection )
414
426
->onQueue ($ this ->queue );
415
427
}
416
428
@@ -425,6 +437,7 @@ public function queueEcommerceCartUpdate(float $grandTotal)
425
437
dispatch (function () use ($ grandTotal ) {
426
438
$ this ->doTrackEcommerceCartUpdate ($ grandTotal );
427
439
})
440
+ ->onConnection ($ this ->queueConnection )
428
441
->onQueue ($ this ->queue );
429
442
}
430
443
@@ -464,6 +477,7 @@ public function queueEcommerceOrder(
464
477
$ discount
465
478
);
466
479
})
480
+ ->onConnection ($ this ->queueConnection )
467
481
->onQueue ($ this ->queue );
468
482
}
469
483
@@ -476,6 +490,7 @@ public function queueBulkTrack()
476
490
dispatch (function () {
477
491
$ this ->doBulkTrack ();
478
492
})
493
+ ->onConnection ($ this ->queueConnection )
479
494
->onQueue ($ this ->queue );
480
495
}
481
496
0 commit comments