Facebook Pixel: Shop API / Headless
Facebook Pixel plugin for Sylius: read-only Shop API endpoint for headless storefronts, response fields and the boundary to the server-side Conversions API.
Facebook Pixel: Shop API / Headless
Live Demo: Try this and other plugins live — no installation, no risk: demo.markus-michalski.net
Endpoint
| Method | Path | Description |
|---|---|---|
| GET | /api/v2/shop/facebook-pixel/settings |
The pixel settings of the current channel, read-only. |
A headless client that does not render the Twig-hooked storefront uses this endpoint to decide whether to fire the pixel itself and for which events. It is the same channel configuration the storefront hooks read. As with any Shop API request, the channel comes from the channel context (the request host). The resource is only registered when API Platform is active in the shop.
Request
curl -H "Accept: application/ld+json" https://shop.example.com/api/v2/shop/facebook-pixel/settings
Response
A channel without a settings row, with tracking switched off or without a valid Pixel ID answers with an unambiguous enabled: false, never a 404. It is the same "off until configured" contract as in the storefront:
{
"channelCode": "WEB",
"pixelId": null,
"enabled": false,
"trackPageView": false,
"trackViewContent": false,
"trackViewCategory": false,
"trackAddToCart": false,
"trackInitiateCheckout": false,
"trackPurchase": false,
"useKlaroConsent": false
}
A configured and enabled channel:
{
"channelCode": "WEB",
"pixelId": "555666777",
"enabled": true,
"trackPageView": true,
"trackViewContent": true,
"trackViewCategory": true,
"trackAddToCart": true,
"trackInitiateCheckout": true,
"trackPurchase": false,
"useKlaroConsent": true
}
With Accept: application/ld+json, API Platform adds the usual JSON-LD fields (@context, @id, @type).
| Field | Type | Description |
|---|---|---|
channelCode |
string | The identifier of this resource; the code of the current channel. |
pixelId |
string or null | The numeric Meta Pixel ID, or null while the channel is not active. |
enabled |
boolean | true when the master switch is on and a valid Pixel ID is set. |
trackPageView ... trackPurchase |
boolean | Which browser events are on for this channel. |
useKlaroConsent |
boolean | The effective gating (stored box AND Klaro installed). A headless client should wait for consent to facebook_pixel when this is true. |
The Conversions API access token, the consent-requirement setting and all other purely server-side settings are never exposed here.
Boundary to the Conversions API
The endpoint only returns settings. There is no endpoint through which a headless client could hand events to the server-side CAPI. The CAPI copies are created when the Twig storefront renders (Twig hooks) and, for AddToCart, in the listener on the Sylius event sylius.cart_item_post_add. A headless frontend without Twig rendering therefore does not trigger server-side PageView, ViewContent, ViewCategory, InitiateCheckout or Purchase events.