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

Commit 026c766

Browse files
committed
Update README.md
1 parent cfa8efc commit 026c766

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ https://twitter.com/pascalbaljet/status/1257926601339277312
88

99
Laravel package to easily send events to Google Analytics
1010

11+
## Features
12+
* Compatible with Laravel 6.0 and 7.0.
13+
* PHP 7.4 required.
14+
1115
## Installation
1216

1317
You can install the package via composer:
@@ -16,10 +20,87 @@ You can install the package via composer:
1620
composer require protonemedia/laravel-analytics-event-tracking
1721
```
1822

19-
## Usage
23+
## Configuration
24+
25+
Publish the config and view files:
26+
27+
```bash
28+
php artisan vendor:publish --provider="ProtoneMedia\AnalyticsEventTracking\ServiceProvider"
29+
```
30+
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.
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!
2040

2141
``` 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+
}
2298

99+
public function broadcastAnalyticsActionAs(Analytics $analytics)
100+
{
101+
return 'CustomEventAction';
102+
}
103+
}
23104
```
24105

25106
### Testing

0 commit comments

Comments
 (0)