Skip to content

Commit 71b8e7f

Browse files
authored
Register the event listener after all providers have booted
This allows for dynamic config values to take effect
1 parent 05fe54a commit 71b8e7f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/ServiceProvider.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ public function boot(): void
3131
$this->bootForConsole();
3232
}
3333

34-
// Only register the listener if the measurement_id and api_secret are set
35-
// to avoid unnecessary overhead.
36-
if (config('ga4-event-tracking.measurement_id') !== null
37-
&& !config('ga4-event-tracking.api_secret') !== null
38-
) {
39-
Event::listen(ShouldBroadcastToAnalytics::class, DispatchAnalyticsJob::class);
40-
}
34+
$this->app->booted(function () {
35+
// Only register the listener if the measurement_id and api_secret are set
36+
// to avoid unnecessary overhead.
37+
if (config('ga4-event-tracking.measurement_id') !== null
38+
&& !config('ga4-event-tracking.api_secret') !== null
39+
) {
40+
Event::listen(ShouldBroadcastToAnalytics::class, DispatchAnalyticsJob::class);
41+
}
42+
});
4143

4244
Blade::directive('sendGA4ClientID', function () {
4345
return "<?php echo view('ga4-event-tracking::sendClientID'); ?>";

0 commit comments

Comments
 (0)