Reporting conversions server-side
Report conversions to Styrar from your own backend in Node.js, Python, or Ruby on Rails.
If a conversion happens on your backend instead of in the browser — a webhook from your payment provider, for example — read the styrar_ck value off the original request and post it directly to the same public endpoint the browser pixel uses. See Conversion pixel for the full reference.
RequestPOST
Content-Type: application/json
{
"clickToken": "the styrar_ck value",
"eventName": "purchase",
"value": 49.99
}Node.js / Express
JavaScript
app.get('/checkout/complete', async (req, res) => {
const clickToken = req.query.styrar_ck || req.cookies?.styrar_ck;
if (clickToken) {
fetch('https://api.styrar.com/v1/pixel/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ clickToken, eventName: 'purchase', value: req.session.orderTotal }),
}).catch(() => {});
}
res.render('checkout-complete');
});
Python (Flask)
PYTHON
import requests
@app.route('/checkout/complete')
def checkout_complete():
click_token = request.args.get('styrar_ck') or request.cookies.get('styrar_ck')
if click_token:
try:
requests.post(
'https://api.styrar.com/v1/pixel/track',
json={'clickToken': click_token, 'eventName': 'purchase', 'value': order_total},
timeout=2,
)
except requests.RequestException:
pass
return render_template('checkout-complete.html')
Python (Django)
PYTHON
import requests
def checkout_complete(request):
click_token = request.GET.get('styrar_ck') or request.COOKIES.get('styrar_ck')
if click_token:
try:
requests.post(
'https://api.styrar.com/v1/pixel/track',
json={'clickToken': click_token, 'eventName': 'purchase', 'value': order_total},
timeout=2,
)
except requests.RequestException:
pass
return render(request, 'checkout-complete.html')
Ruby on Rails
RUBY
require 'net/http'
require 'json'
class CheckoutController < ApplicationController
def complete
click_token = params[:styrar_ck] || cookies[:styrar_ck]
if click_token
begin
uri = URI('https://api.styrar.com/v1/pixel/track')
Net::HTTP.post(uri, { clickToken: click_token, eventName: 'purchase', value: @order_total }.to_json,
'Content-Type' => 'application/json')
rescue StandardError
nil
end
end
end
end
Any other backend
The endpoint is plain HTTP and JSON with no authentication, so this works from any language that can make an HTTP request:
Shell
curl -X POST https://api.styrar.com/v1/pixel/track \
-H 'Content-Type: application/json' \
-d '{"clickToken":"<styrar_ck value>","eventName":"purchase","value":49.99}'
Wrap the call so a tracking failure can never break the flow it's attached to — the endpoint always returns 200 { "ok": true }, but you should still catch network errors on your end.