1- # Conversions API parameter builder for PHP
1+ # Conversions API parameter builder feature for PHP
22
33[ ![ Packagist] ( https://img.shields.io/packagist/v/facebook/capi-param-builder-php )] ( https://packagist.org/packages/facebook/capi-param-builder-php )
44[ ![ License] ( https://img.shields.io/badge/license-Facebook%20Platform-blue.svg?style=flat-square )] ( https://github.com/facebook/capi-param-builder/blob/main/php/LICENSE )
55
66## Introduction
77
8- Conversions API parameter builder SDK is a lightweight tool for improving
8+ The Conversions API parameter builder SDK is a lightweight tool for improving
99Conversions API parameter retrieval and quality.
1010
1111[ Server-Side Parameter Builder Onboarding Guide] ( https://developers.facebook.com/docs/marketing-api/conversions-api/parameter-builder-feature-library/server-side-onboarding )
1212
1313## Quick start
1414
15- Here is a quick-start guide for integrating parameter builder into your code.
16- You can find a demo in the next section.
15+ Here is a quick-start guide for integrating the parameter builder feature into
16+ your code. You can find a demo in the next section.
1717
1818### Setup
1919
20201 . Check the latest version in CHANGELOG. Modify below {current_version} into
2121 latest version number.
2222
23- 2 . Update in your composer.json .
23+ 2 . Update in your composer.json with the latest version .
2424
2525```
26- "require": {
27- "php": ">=7.4",
28- "facebook/capi-param-builder-php": "{current_version}"
29- },
26+ "require": {
27+ "php": ">=7.4",
28+ "facebook/capi-param-builder-php": "{current_version}"
29+ },
3030```
3131
32- 3 . Install the dependency(if you don't have an application, check #demo section
33- for a demo application)
32+ 3 . Install the dependency. If you don't have an application, check #demo section
33+ for a demo application.
3434
3535```
3636composer install
3737```
3838
39- or update if you need update the version.
39+ or update if you need to update the version.
4040
4141```
4242composer update
4343```
4444
45- Once you finish these steps, your parameter builder integration will be
46- complete. You can see a demo in the following section.
45+ Once you finish these steps, the setup step of your parameter builder
46+ integration is complete. You can see a demo in the following section.
4747
4848### Demo
4949
@@ -52,13 +52,13 @@ the library, feel free to skip this section.
5252
53531 . Checkout the examples for localhost demo and Drupal demo under ./examples
5454
55- 2 . Take localhost as an example, go to ./examples/local. Update the dependency
56- by running
55+ 2 . Take localhost as an example, go to ./examples/local. Install or update the
56+ dependency by running
5757
5858```
59- composer install
60- or
61- composer update
59+ composer install
60+ or
61+ composer update
6262```
6363
64643 . Start the server
@@ -74,16 +74,18 @@ php -S localhost:8000
7474Following are some further validations:
7575
76764.1 Go to http://localhost:8000/demo.php?fbclid=thisIsATest123 . The printed
77- ` fbc ` and ` fbp ` are not null. And the ` fbc ` should have a portion containing
78- ` thisIsATest123 ` . Check the cookies' value, is the same as printed.
77+ ` fbc ` and ` fbp ` should be present and not null. The printed ` fbc ` should have a
78+ portion containing ` thisIsATest123 ` . Please also validate that the corresponding
79+ respective cookie values, ‘\_ fbc’ and ‘\_ fbp’, are the same as printed ` fbc ` and
80+ ` fbp ` .
7981
80- 4.2 Go to http://localhost:8000/demo.php . The printed ` fbc ` and ` fbp ` , as well
81- as the cookies' value, should be the same as 4.1.
82+ 4.2 Go to http://localhost:8000/demo.php . Please validate that printed ` fbc ` and
83+ ` fbp ` and corresponding cookie values, ‘\_ fbc’ and ‘\_ fbp’ are the same as those
84+ in step 4.1.
8285
8386## API usage
8487
85- This section explains how to use the SDK. And provide suggestions on the API
86- usage.
88+ This section explains how to use the APIs provided in the SDK.
8789
88901 . Integrate the library as #Quick start section mentioned above.
89912 . Import the parameter builder and build the constructor. The ETLD+1 can help
@@ -93,39 +95,41 @@ Option 1 (recommended): input ELTD+1 domain list. We'll compare your current
9395host name and provide the domain we recommended to save your cookie.
9496
9597```
96- $param_builder = new FacebookAds\ParamBuilder(array('example.com', 'test.com'));
98+ $param_builder = new FacebookAds\ParamBuilder(array('example.com', 'test.com'));
9799```
98100
99101Option 2: Customized ETLD+1 resolver. Create a file implementing
100102ETLDPlus1Resolver. Example: ETLDPlus1ResolverForTest.php under ./examples/local.
101103
102104```
103- $param_builder = new FacebookAds\ParamBuilder(new ETLDPlus1ResolverForTest());
105+ $param_builder = new FacebookAds\ParamBuilder(new ETLDPlus1ResolverForTest());
104106```
105107
106108Option 3: Not recommended. We'll do a simple check to return one level down
107109subdomain. Eg. your input is test.example.demo.com, we'll return
108110example.demo.com. This option may be less accurate.
109111
110112```
111- $param_builder = new FacebookAds\ParamBuilder();
113+ $param_builder = new FacebookAds\ParamBuilder();
112114```
113115
114- 3 . Call ` processRequest ` to process the fbc, fbp.
116+ 3 . Call ` processRequest ` to process fbc, fbp and fbi(client_ip_address) .
115117
116118```
117119$param_builder->processRequest(
118- $host_name, // string for full url
119- $url_query_params, // map for query params
120- $cookie, // map for cookies
121- $referral_link // (optional, nullable)string, full referral link to help improve potential the event quality.
120+ $host_name, // string for full url
121+ $url_query_params, // map for query params
122+ $cookie, // map for cookies
123+ $referral_link, // (optional, nullable)string, full referral link to help improve potential event quality.
124+ $x_forwarded_for, // (optional, nullable)string, the http x_forwarded_for request header.
125+ $remote_address // (optional, nullable)string, the remote_address variable in http request.
122126);
123127```
124128
125- 4 . [ Recommended] Save the ` $cookie_to_set ` as first-party cookies to help keep
126- fbc and fbp consistent among all events. Based on your webserver framework,
127- the save cookie API may vary. Feel free to choose the best fit for your use
128- case. Below uses the example from the demo application.
129+ 4 . [ Recommended] Save the ` $cookie_to_set ` as first-party cookies to keep fbc
130+ and fbp consistent across all events. Based on your webserver framework, the
131+ save cookie API may vary. Feel free to choose the best fit for your use case.
132+ Below is one example excerpted from the demo application.
129133
130134Recommended: get ` $cookie_to_set ` from API call in step 3.
131135
@@ -143,47 +147,76 @@ Call setcookie from the server side to have the cookies saved.
143147
144148```
145149foreach ($cookie_to_set as $cookie) {
146- setcookie(
147- $cookie->name,
148- $cookie->value,
149- time() + $cookie->max_age,
150- '/',
151- $cookie->domain);
150+ setcookie(
151+ $cookie->name,
152+ $cookie->value,
153+ time() + $cookie->max_age,
154+ '/',
155+ $cookie->domain);
152156}
153157```
154158
155159If there is no change to your current cookies, the returned list will be empty.
156160
157- 5 . Get fbc and fbp
161+ 5 . Get fbc/fbp, client_ip_address, normalized and hashed PII values
158162
159163```
160164
165+
161166$fbc = $param_builder->getFbc();
162167
163- ```
164168
165169```
166170
167171$fbp = $param_builder->getFbp();
168172
169173```
170174
171- 6 . Send fbc and fbp back with Conversions API.
175+
176+ $client_ip_address = $param_builder->getClientIpAddress();
177+
178+
179+ ```
180+
181+ $email = $param_builder->getNormalizedAndHashedPII('
182+ John_Smith@gmail.com ','email');
183+
184+ ```
185+
186+
187+ $phone = $param_builder->getNormalizedAndHashedPII('+1 (616) 954-78 88','phone');
188+
189+
190+ ```
191+
192+ getNormalizedAndHashedPII(piiValue, dataType)
193+
194+ ```
195+ API is to get normalized and hashed (sha256) PII from input piiValue, supported dataType include 'phone', 'email', 'first_name', 'last_name', 'date_of_birth', 'gender', 'city', 'state', 'zip_code', 'country' and 'external_id'.
196+
197+
198+ ```
199+
200+ 6 . Send fbc, fbp, client_ip_address, email and phone back through Conversions
201+ API.
172202
173203```
174204data=[
175- 'event_name: '...',
176- 'event_tme': <your_time>,
177- 'user_data': {
178- 'fbc': fbc, // The value provided in step 5
179- 'fbp': fbp, // The value provided in step 5
180- ...
181- }
182- ...
205+ 'event_name: '...',
206+ 'event_time': <your_time>,
207+ 'user_data': {
208+ 'fbc': $fbc, // The value provided in step 5
209+ 'fbp': $fbp, // The value provided in step 5
210+ 'client_ip_address': $client_ip_address // The value provided in step 5
211+ 'em': $email // The value provided in step 5
212+ 'ph': $phone // The value provided in step 5
213+ ...
214+ }
215+ ...
183216]
184217```
185218
186219## License
187220
188- Conversions API parameter builder for PHP is licensed under the LICENSE file in
189- the root directory of this source tree.
221+ The Conversions API parameter builder feature for PHP is licensed under the
222+ LICENSE file in the root directory of this source tree.
0 commit comments