Skip to content

Commit

Permalink
Merge pull request #3 from tbruckmaier/master
Browse files Browse the repository at this point in the history
Queue improvements
  • Loading branch information
alfrasc authored Nov 18, 2021
2 parents b1d3075 + ffb5528 commit dd9e82c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
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
17 changes: 16 additions & 1 deletion 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 All @@ -45,7 +48,8 @@ private function setMatomoVariables(Request $request, int $idSite = null, string
$this->ecommerceItems = array();
$this->attributionInfo = false;
$this->eventCustomVar = false;
$this->forcedDatetime = false;
// force-set time, so queued commands use the right request time
$this->forcedDatetime = time();
$this->forcedNewVisit = false;
$this->networkTime = false;
$this->serverTime = false;
Expand Down Expand Up @@ -302,6 +306,7 @@ public function queuePageView(string $documentTitle)
dispatch(function () use ($documentTitle) {
$this->doTrackPageView($documentTitle);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

Expand All @@ -319,6 +324,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 +341,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 +359,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 +376,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 +392,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 +407,7 @@ public function queueDownload(string $actionUrl)
dispatch(function () use ($actionUrl) {
$this->doTrackDownload($actionUrl);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

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

Expand All @@ -425,6 +437,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 +477,7 @@ public function queueEcommerceOrder(
$discount
);
})
->onConnection($this->queueConnection)
->onQueue($this->queue);
}

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

Expand Down

0 comments on commit dd9e82c

Please sign in to comment.