Render JavaScript tracking code for a product.
POST /json/renderJsTrackingCode
[
'result' => 'success',
'data' => [
'product_id' => 123,
'tracking_code' => '<script>
// Google Analytics tracking
gtag("event", "purchase", {
transaction_id: "ABCD1234",
value: 99.00,
currency: "EUR",
items: [{
item_id: "123",
item_name: "Premium Course",
price: 99.00,
quantity: 1
}]
});
// Facebook Pixel tracking
fbq("track", "Purchase", {
value: 99.00,
currency: "EUR",
content_ids: ["123"],
content_type: "product"
});
</script>'
]
]
use GoSuccess\Digistore24\Api\Digistore24;
use GoSuccess\Digistore24\Api\Client\Configuration;
// Initialize API client
$config = new Configuration('YOUR-API-KEY');
$api = new Digistore24($config);
// Get tracking code for product
$response = $api->tracking()->renderJsTrackingCode(
productId: 123
);
echo "Tracking Code:\n";
echo $response->trackingCode;
// Get tracking code with purchase details
$response = $api->tracking()->renderJsTrackingCode(
productId: 123,
purchaseId: 'ABCD1234',
amount: 99.00,
currency: 'EUR'
);
// Output tracking code to page
echo $response->trackingCode;
// Example: Embed in thank-you page
$trackingCode = $response->trackingCode;
echo <<<HTML
<!DOCTYPE html>
<html>
<head>
<title>Thank You</title>
</head>
<body>
<h1>Thank you for your purchase!</h1>
{$trackingCode}
</body>
</html>
HTML;