Skip to content

Commit

Permalink
Make queue connection configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruckmaier committed Mar 29, 2021
1 parent b1d3075 commit ccf870e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion config/matomotracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
/**
* For queuing the tracking you can use custom queue names. Use 'default' if you want to run the queued items within the standard queue.
*/
'queue' => env('MATOMO_QUEUE', 'matomotracker')
'queue' => env('MATOMO_QUEUE', 'matomotracker'),

/**
* Optionally set a custom queue connection. Laravel defaults to "sync".
*/
'queueConnection' => env('MATOMO_QUEUE_CONNECTION', 'default'),
];
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ MATOMO_URL="https://your.matomo-install.com"
MATOMO_SITE_ID=1
MATOMO_AUTH_TOKEN="00112233445566778899aabbccddeeff"
MATOMO_QUEUE="matomotracker"
MATOMO_QUEUE_CONNECTION="default"
[...]
```

Expand Down
14 changes: 14 additions & 0 deletions src/LaravelMatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ class LaravelMatomoTracker extends MatomoTracker
protected $tokenAuth;
/** @var string */
protected $queue;
/** @var string */
protected $queueConnection;

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

$this->setTokenAuth(!is_null($tokenAuth) ? $tokenAuth : config('matomotracker.tokenAuth'));
$this->setMatomoVariables($request, $idSite, $apiUrl);
Expand Down Expand Up @@ -302,6 +305,7 @@ public function queuePageView(string $documentTitle)
dispatch(function () use ($documentTitle) {
$this->doTrackPageView($documentTitle);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -319,6 +323,7 @@ public function queueEvent(string $category, string $action, $name = false, $val
dispatch(function () use ($category, $action, $name, $value) {
$this->doTrackEvent($category, $action, $name, $value);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -335,6 +340,7 @@ public function queueContentImpression(string $contentName, string $contentPiece
dispatch(function () use ($contentName, $contentPiece, $contentTarget) {
$this->doTrackContentImpression($contentName, $contentPiece, $contentTarget);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -352,6 +358,7 @@ public function queueContentInteraction(string $interaction, string $contentName
dispatch(function () use ($interaction, $contentName, $contentPiece, $contentTarget) {
$this->doTrackContentInteraction($interaction, $contentName, $contentPiece, $contentTarget);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -368,6 +375,7 @@ public function queueSiteSearch(string $keyword, string $category = '', $countR
dispatch(function () use ($keyword, $category, $countResults) {
$this->doTrackSiteSearch($keyword, $category, $countResults);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -383,6 +391,7 @@ public function queueGoal($idGoal, $revencue = 0.0)
dispatch(function () use ($idGoal, $revencue) {
$this->doTrackGoal($idGoal, $revencue);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -397,6 +406,7 @@ public function queueDownload(string $actionUrl)
dispatch(function () use ($actionUrl) {
$this->doTrackDownload($actionUrl);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -411,6 +421,7 @@ public function queueOutlink(string $actionUrl)
dispatch(function () use ($actionUrl) {
$this->doTrackOutlink($actionUrl);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -425,6 +436,7 @@ public function queueEcommerceCartUpdate(float $grandTotal)
dispatch(function () use ($grandTotal) {
$this->doTrackEcommerceCartUpdate($grandTotal);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand Down Expand Up @@ -464,6 +476,7 @@ public function queueEcommerceOrder(
$discount
);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -476,6 +489,7 @@ public function queueBulkTrack()
dispatch(function () {
$this->doBulkTrack();
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand Down

0 comments on commit ccf870e

Please sign in to comment.