Skip to content

Commit cdd3b42

Browse files
Add: docs
1 parent 07648d0 commit cdd3b42

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

README.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,101 @@ Next up, you can publish the configuration file:
1919
php artisan vendor:publish --provider="Esign\ConversionsApi\ConversionsApiServiceProvider" --tag="config"
2020
```
2121

22-
## Usage
22+
The config file will be published as config/conversions-api.php with the following content:
23+
```php
24+
return [
25+
/**
26+
* The access token used by the Conversions API.
27+
*/
28+
'access_token' => env('CONVERSIONS_API_ACCESS_TOKEN'),
2329

24-
<!-- TODO -->
30+
/**
31+
* The pixel ID used by the Conversions API.
32+
*/
33+
'pixel_id' => env('CONVERSIONS_API_PIXEL_ID'),
34+
35+
/**
36+
* The Conversions API comes with a nice way to test your events.
37+
* You may use this config variable to set your test code.
38+
*/
39+
'test_code' => null,
40+
];
41+
```
42+
43+
## Conversions API
44+
45+
This package allows you to set the user data and events that will be sent to the Conversions API.
46+
```php
47+
use Esign\ConversionsApi\Facades\ConversionsApi;
48+
use FacebookAds\Object\ServerSide\UserData;
49+
use FacebookAds\Object\ServerSide\Event;
50+
51+
ConversionsApi::setUserData(
52+
(new UserData())->setFirstName('John')->setLastName('Doe')
53+
);
54+
ConversionsApi::setEvent(
55+
(new Event())->setEventName('PageView')->setEventId('abc')
56+
);
57+
```
58+
59+
To actually send the data you must call the `execute` method.
60+
```php
61+
use Esign\ConversionsApi\Facades\ConversionsApi;
62+
63+
ConversionsApi::execute();
64+
```
65+
66+
This package also comes with a nice helper to send `PageView` events.
67+
By including the `@conversionsApiPageView` directive on a page, an event with the minimum required data (ip address, user agent and request url) will be sent to the Conversions API:
68+
```php
69+
@conversionsApiPageView
70+
```
71+
72+
###
73+
74+
## Facebook Pixel
75+
To [deduplicate browser and server events](https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events/) this package will automatically generate a unique event ID for every request.
76+
This event ID should be passed along with your Facebook Pixel.
77+
This package comes with a few ways to do this:
78+
79+
### Facebook Pixel
80+
In case you want to directly load the Facebook Pixel script you may use the `@conversionsApiFacebookPixelScript` directive or directly include it.
81+
```php
82+
@conversionsApiFacebookPixelScript
83+
@include('conversions-api::facebook-pixel-script')
84+
```
85+
86+
### Google Tag Manager
87+
A convenient dataLayer helper is included in case you want to load the Facebook Pixel through Google Tag Manager.
88+
By default a variable name `conversionsApiEventId` will be used:
89+
```php
90+
@conversionsApiDataLayer
91+
@include('conversions-api::data-layer')
92+
```
93+
94+
You may also pass a custom variable name:
95+
```php
96+
@conversionsApiDataLayer('yourDataLayerVariableName')
97+
@include('conversions-api::data-layer', ['dataLayerVariableName' => 'yourDataLayerVariableName'])
98+
```
99+
100+
#### Configuring Google Tag Manager
101+
First off, you should add a new `Data Layer Variable` to your Google Tag Manager workspace.
102+
![1](docs/images/gtm-step-1.png)
103+
104+
Next up you should use the variable name that was passed along to the data layer view.
105+
![2](docs/images/gtm-step-2.png)
106+
107+
After saving the variable you should be able to use it in your Facebook Pixel script using the double bracket syntax: `{{ Name of your variable }}`.
108+
![3](docs/images/gtm-step-3.png)
109+
110+
### Manually retrieving the event ID
111+
In case you want to use another strategy to deduplicate your events you can do so by manually retrieving the event ID:
112+
```php
113+
use Esign\ConversionsApi\Facades\ConversionsApi;
114+
115+
ConversionsApi::getEventId();
116+
```
25117

26118
## Testing
27119

docs/images/gtm-step-1.png

231 KB
Loading

docs/images/gtm-step-2.png

84.5 KB
Loading

docs/images/gtm-step-3.png

216 KB
Loading

0 commit comments

Comments
 (0)