You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
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.
32
+
33
+
```bash
34
+
GOOGLE_ANALYTICS_TRACKING_ID=UA-01234567-89
35
+
```
36
+
37
+
## Broadcast Events to Google Analytics
38
+
39
+
Just add the `ShouldBroadcastToAnalytics` interface to your event and you're ready!
20
40
21
41
```php
42
+
<?php
43
+
44
+
namespace App\Events;
45
+
46
+
use App\Order;
47
+
use Illuminate\Foundation\Events\Dispatchable;
48
+
use Illuminate\Queue\SerializesModels;
49
+
use ProtoneMedia\AnalyticsEventTracking\Events\ShouldBroadcastToAnalytics;
50
+
51
+
class OrderWasPaid implements ShouldBroadcastToAnalytics
52
+
{
53
+
use Dispatchable, SerializesModels;
54
+
55
+
public $order;
56
+
57
+
public function __construct(Order $order)
58
+
{
59
+
$this->order = $order;
60
+
}
61
+
}
62
+
```
63
+
64
+
## Customize the broadcast
65
+
66
+
There are two additional methods that lets you customize the call to Google Analytics.
67
+
68
+
With the `withAnalytics` you can interact with the [underlying package](https://github.com/theiconic/php-ga-measurement-protocol) to set additional parameters. Take a look at the `TheIconic\Tracking\GoogleAnalytics\Analytics` class to see the available methods.
69
+
70
+
With the `broadcastAnalyticsActionAs` you can customize the name of the [Event Action](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#eventAction). By default we use the class name with the class's namespace removed. This method gives you access to the underlying `Analytics` class as well.
71
+
72
+
```php
73
+
<?php
74
+
75
+
namespace App\Events;
76
+
77
+
use App\Order;
78
+
use TheIconic\Tracking\GoogleAnalytics\Analytics;
79
+
use Illuminate\Foundation\Events\Dispatchable;
80
+
use Illuminate\Queue\SerializesModels;
81
+
use ProtoneMedia\AnalyticsEventTracking\Events\ShouldBroadcastToAnalytics;
82
+
83
+
class OrderWasPaid implements ShouldBroadcastToAnalytics
84
+
{
85
+
use Dispatchable, SerializesModels;
86
+
87
+
public $order;
88
+
89
+
public function __construct(Order $order)
90
+
{
91
+
$this->order = $order;
92
+
}
93
+
94
+
public function withAnalytics(Analytics $analytics)
95
+
{
96
+
$analytics->setEventValue(100);
97
+
}
22
98
99
+
public function broadcastAnalyticsActionAs(Analytics $analytics)
0 commit comments