Skip to content

Commit dd9e82c

Browse files
authored
Merge pull request #3 from tbruckmaier/master
Queue improvements
2 parents b1d3075 + ffb5528 commit dd9e82c

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

config/matomotracker.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@
2020
/**
2121
* For queuing the tracking you can use custom queue names. Use 'default' if you want to run the queued items within the standard queue.
2222
*/
23-
'queue' => env('MATOMO_QUEUE', 'matomotracker')
23+
'queue' => env('MATOMO_QUEUE', 'matomotracker'),
24+
25+
/**
26+
* Optionally set a custom queue connection. Laravel defaults to "sync".
27+
*/
28+
'queueConnection' => env('MATOMO_QUEUE_CONNECTION', 'default'),
2429
];

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ MATOMO_URL="https://your.matomo-install.com"
3939
MATOMO_SITE_ID=1
4040
MATOMO_AUTH_TOKEN="00112233445566778899aabbccddeeff"
4141
MATOMO_QUEUE="matomotracker"
42+
MATOMO_QUEUE_CONNECTION="default"
4243
[...]
4344
```
4445

src/LaravelMatomoTracker.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ class LaravelMatomoTracker extends MatomoTracker
1717
protected $tokenAuth;
1818
/** @var string */
1919
protected $queue;
20+
/** @var string */
21+
protected $queueConnection;
2022

2123
public function __construct(?Request $request, ?int $idSite = null, ?string $apiUrl = null, ?string $tokenAuth = null)
2224
{
2325
$this->tokenAuth = $tokenAuth ?: config('matomotracker.tokenAuth');
2426
$this->queue = config('matomotracker.queue', 'matomotracker');
27+
$this->queueConnection = config('matomotracker.queueConnection', 'default');
2528

2629
$this->setTokenAuth(!is_null($tokenAuth) ? $tokenAuth : config('matomotracker.tokenAuth'));
2730
$this->setMatomoVariables($request, $idSite, $apiUrl);
@@ -45,7 +48,8 @@ private function setMatomoVariables(Request $request, int $idSite = null, string
4548
$this->ecommerceItems = array();
4649
$this->attributionInfo = false;
4750
$this->eventCustomVar = false;
48-
$this->forcedDatetime = false;
51+
// force-set time, so queued commands use the right request time
52+
$this->forcedDatetime = time();
4953
$this->forcedNewVisit = false;
5054
$this->networkTime = false;
5155
$this->serverTime = false;
@@ -302,6 +306,7 @@ public function queuePageView(string $documentTitle)
302306
dispatch(function () use ($documentTitle) {
303307
$this->doTrackPageView($documentTitle);
304308
})
309+
->onConnection($this->queueConnection)
305310
->onQueue($this->queue);
306311
}
307312

@@ -319,6 +324,7 @@ public function queueEvent(string $category, string $action, $name = false, $val
319324
dispatch(function () use ($category, $action, $name, $value) {
320325
$this->doTrackEvent($category, $action, $name, $value);
321326
})
327+
->onConnection($this->queueConnection)
322328
->onQueue($this->queue);
323329
}
324330

@@ -335,6 +341,7 @@ public function queueContentImpression(string $contentName, string $contentPiece
335341
dispatch(function () use ($contentName, $contentPiece, $contentTarget) {
336342
$this->doTrackContentImpression($contentName, $contentPiece, $contentTarget);
337343
})
344+
->onConnection($this->queueConnection)
338345
->onQueue($this->queue);
339346
}
340347

@@ -352,6 +359,7 @@ public function queueContentInteraction(string $interaction, string $contentName
352359
dispatch(function () use ($interaction, $contentName, $contentPiece, $contentTarget) {
353360
$this->doTrackContentInteraction($interaction, $contentName, $contentPiece, $contentTarget);
354361
})
362+
->onConnection($this->queueConnection)
355363
->onQueue($this->queue);
356364
}
357365

@@ -368,6 +376,7 @@ public function queueSiteSearch(string $keyword, string $category = '', $countR
368376
dispatch(function () use ($keyword, $category, $countResults) {
369377
$this->doTrackSiteSearch($keyword, $category, $countResults);
370378
})
379+
->onConnection($this->queueConnection)
371380
->onQueue($this->queue);
372381
}
373382

@@ -383,6 +392,7 @@ public function queueGoal($idGoal, $revencue = 0.0)
383392
dispatch(function () use ($idGoal, $revencue) {
384393
$this->doTrackGoal($idGoal, $revencue);
385394
})
395+
->onConnection($this->queueConnection)
386396
->onQueue($this->queue);
387397
}
388398

@@ -397,6 +407,7 @@ public function queueDownload(string $actionUrl)
397407
dispatch(function () use ($actionUrl) {
398408
$this->doTrackDownload($actionUrl);
399409
})
410+
->onConnection($this->queueConnection)
400411
->onQueue($this->queue);
401412
}
402413

@@ -411,6 +422,7 @@ public function queueOutlink(string $actionUrl)
411422
dispatch(function () use ($actionUrl) {
412423
$this->doTrackOutlink($actionUrl);
413424
})
425+
->onConnection($this->queueConnection)
414426
->onQueue($this->queue);
415427
}
416428

@@ -425,6 +437,7 @@ public function queueEcommerceCartUpdate(float $grandTotal)
425437
dispatch(function () use ($grandTotal) {
426438
$this->doTrackEcommerceCartUpdate($grandTotal);
427439
})
440+
->onConnection($this->queueConnection)
428441
->onQueue($this->queue);
429442
}
430443

@@ -464,6 +477,7 @@ public function queueEcommerceOrder(
464477
$discount
465478
);
466479
})
480+
->onConnection($this->queueConnection)
467481
->onQueue($this->queue);
468482
}
469483

@@ -476,6 +490,7 @@ public function queueBulkTrack()
476490
dispatch(function () {
477491
$this->doBulkTrack();
478492
})
493+
->onConnection($this->queueConnection)
479494
->onQueue($this->queue);
480495
}
481496

0 commit comments

Comments
 (0)