Passing mk_cid to the order
For the website developer: keep the click mark and send a signed event after payment. Example in PHP / Laravel.
The idea
01
Landing page
?mk_cid=… in the address
02
Session
Store mk_cid
03
Order
Save mk_cid with the order
04
Payment
POST a signed purchase event
mk_cid is 22 Latin letters and digits. In redirect mode it is added to the landing page address by the tracking domain; in direct and parallel modes the website gets it from the visit endpoint or sends the platform click id instead.
Step 1. Keep mk_cid in the session
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class CaptureMkCid
{
public function handle(Request $request, Closure $next)
{
$cid = $request->query('mk_cid');
if (is_string($cid) && preg_match('/^[A-Za-z0-9]{22}$/', $cid)) {
$request->session()->put('mk_cid', $cid);
}
return $next($request);
}
}Register the middleware in the web group so it runs on every page.
Step 2. Save it with the order
// Migration: $table->string('mk_cid', 22)->nullable();
$order->mk_cid = session('mk_cid');
$order->save();Step 3. Send a signed event after payment
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class Loomark
{
public static function send(array $event): void
{
// Sign exactly the bytes you send.
$body = json_encode(['events' => [$event]], JSON_UNESCAPED_SLASHES);
$ts = (string) time();
$sig = hash_hmac('sha256', $ts . '.' . $body, config('services.loomark.secret'));
Http::withHeaders([
'X-S2S-Key' => config('services.loomark.key'),
'X-S2S-Timestamp' => $ts,
'X-S2S-Signature' => 'sha256=' . $sig,
])
->withBody($body, 'application/json')
->post(config('services.loomark.endpoint'));
}
}Loomark::send([
'event' => 'purchase',
'event_id' => 'order-' . $order->id,
'mk_cid' => $order->mk_cid,
'order_id' => (string) $order->id,
'value' => (float) $order->total,
'currency' => 'EUR',
]);Put the key, the secret and the events address from the source window into config/services.php through environment variables, never into the code.
Step 4. Check
- Step 1Add
'test' => trueto the event and run a test order. - Step 2Open Tracking → Events: the event appears marked “test”.
- Step 3Remove
testand go live.
BODY='{"events":[{"event":"purchase","event_id":"order-1001","mk_cid":"<mk_cid>","order_id":"1001","value":129.9,"currency":"EUR","test":true}]}'
TS=$(date +%s)
SIG=$(printf "%s.%s" "$TS" "$BODY" | openssl dgst -sha256 -hmac '<secret>' | sed 's/^.* //')
curl -X POST <events address> -H 'Content-Type: application/json' -H 'X-S2S-Key: <key>' -H "X-S2S-Timestamp: $TS" -H "X-S2S-Signature: sha256=$SIG" -d "$BODY"Common errors
| Answer | Cause |
|---|---|
401 signature_expired | The timestamp differs from the server time by more than 5 minutes — check NTP |
401 signature_invalid | The signature was computed over different bytes than were sent, or with another secret |
401 unauthorized | Wrong or deleted key |
400 invalid_payload | The body is not {"events": [...]} with 1–100 events |
413 payload_too_large | The body is larger than 512 KB |
A 200 answer has counters accepted, duplicates, unmatched (no click found) and a list of rejected events.