Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit f9aacb7

Browse files
committed
Docs + custom queue support
1 parent 026c766 commit f9aacb7

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ Publish the config and view files:
2828
php artisan vendor:publish --provider="ProtoneMedia\AnalyticsEventTracking\ServiceProvider"
2929
```
3030

31-
Set your [Google Analytics tracking ID](https://support.google.com/analytics/answer/1008080) in your `.env` file or in the `config/analytics-event-tracking.php` file.
31+
Set your [Google Analytics Tracking ID](https://support.google.com/analytics/answer/1008080) in the `.env` file or in the `config/analytics-event-tracking.php` file.
3232

3333
```bash
3434
GOOGLE_ANALYTICS_TRACKING_ID=UA-01234567-89
3535
```
3636

3737
## Broadcast Events to Google Analytics
3838

39-
Just add the `ShouldBroadcastToAnalytics` interface to your event and you're ready!
39+
Add the `ShouldBroadcastToAnalytics` interface to your event and you're ready! You don't have to manually bind any listeners.
4040

4141
``` php
4242
<?php
@@ -93,7 +93,7 @@ class OrderWasPaid implements ShouldBroadcastToAnalytics
9393

9494
public function withAnalytics(Analytics $analytics)
9595
{
96-
$analytics->setEventValue(100);
96+
$analytics->setEventValue($this->order->sum_in_cents * 100);
9797
}
9898

9999
public function broadcastAnalyticsActionAs(Analytics $analytics)

config/config.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
<?php
22

33
return [
4+
/**
5+
* Your Google Analytics Tracking ID.
6+
* https://support.google.com/analytics/answer/1008080
7+
*/
48
'tracking_id' => env('GOOGLE_ANALYTICS_TRACKING_ID'),
59

6-
'client_id_session_key' => 'analytics-event-tracker-client-id',
7-
8-
// set to null to disable
9-
'http_uri' => 'gaid',
10-
10+
/**
11+
* Use SSL to make calls to Google Analytics.
12+
*/
1113
'use_ssl' => true,
1214

15+
/**
16+
* Anonymize IP when making calls to Google Analytics.
17+
*/
1318
'anonymize_ip' => true,
1419

20+
/**
21+
* Send the ID of the authenticated user to Google Analytics.
22+
*/
1523
'send_user_id' => true,
24+
25+
/*
26+
* This queue will be used to perform the API calls to Google Analytics.
27+
* Leave empty to use the default queue.
28+
*/
29+
'queue_name' => '',
30+
31+
/**
32+
* The session key to store the Client ID.
33+
*/
34+
'client_id_session_key' => 'analytics-event-tracker-client-id',
35+
36+
/**
37+
* HTTP URI to store the Client ID.
38+
*/
39+
'http_uri' => '/gaid',
1640
];

src/Listeners/DispatchAnalyticsJob.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public function __construct(ClientIdRepostory $clientIdRepository)
2323
*/
2424
public function handle(ShouldBroadcastToAnalytics $event): void
2525
{
26-
SendEventToAnalytics::dispatch($event, $this->clientIdRepository->get());
26+
$job = new SendEventToAnalytics($event, $this->clientIdRepository->get());
27+
28+
if ($queueName = config('analytics-event-tracking.queue_name')) {
29+
$job->onQueue($queueName);
30+
}
31+
32+
dispatch($job);
2733
}
2834
}

tests/EventListenerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,18 @@ public function it_listen_for_events_that_should_be_broadcasted_to_analytics()
1919

2020
Bus::assertDispatchedTimes(SendEventToAnalytics::class, 1);
2121
}
22+
23+
/** @test */
24+
public function it_can_dispatch_jobs_on_a_dedicated_queue()
25+
{
26+
Bus::fake();
27+
28+
config(['analytics-event-tracking.queue_name' => 'http']);
29+
30+
event(new BroadcastMe);
31+
32+
Bus::assertDispatched(SendEventToAnalytics::class, function ($job) {
33+
return $job->queue === 'http';
34+
});
35+
}
2236
}

0 commit comments

Comments
 (0)