Conversion Tracking

Integration guide for developers

What is conversion tracking?

When a visitor completes a meaningful action on your site — a purchase, signup, or form submission — you can tell ClickLens that the session was a real human. This creates verified ground truth that trains the scoring engine to reduce false positives over time. The more conversions you report, the better ClickLens gets at distinguishing your real customers from bot traffic.

How it works

  1. The ClickLens tag stores a session key (cl_sk) in the browser's sessionStorage when a visitor arrives on your site.
  2. After a conversion event, your code reads this key and sends it to the ClickLens API.
  3. ClickLens marks the session as a verified human visitor. This feeds into the efficacy dashboard and improves future scoring accuracy.

Frontend integration

The simplest approach is to call the conversion endpoint from your thank-you or confirmation page. Add this snippet after your conversion event fires:

const sessionKey = sessionStorage.getItem('cl_sk');
if (sessionKey) {
  fetch('https://your-domain.clicklens.io/api/v1/sessions/convert', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_SITE_KEY'
    },
    body: JSON.stringify({ sessionKey })
  });
}

Replace YOUR_SITE_KEY with the site key from your ClickLens dashboard (Settings → Site Settings). The call is fire-and-forget — you don't need to wait for the response.

Backend integration

If your conversion happens server-side (e.g., after payment confirmation from Stripe), pass the session key from the frontend to your server, then call the API from your backend:

Node.js

await fetch('https://your-domain.clicklens.io/api/v1/sessions/convert', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_SITE_KEY'
  },
  body: JSON.stringify({ sessionKey })
});

Python

import requests

requests.post(
    "https://your-domain.clicklens.io/api/v1/sessions/convert",
    json={"sessionKey": session_key},
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_SITE_KEY"
    }
)

cURL

curl -X POST https://your-domain.clicklens.io/api/v1/sessions/convert \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_SITE_KEY" \
  -d '{"sessionKey": "SESSION_KEY_VALUE"}'

Google Tag Manager

To fire the conversion call via GTM, create a Custom HTML tag that triggers on your thank-you page:

<script>
  var sessionKey = sessionStorage.getItem('cl_sk');
  if (sessionKey) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://your-domain.clicklens.io/api/v1/sessions/convert');
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.setRequestHeader('Authorization', 'Bearer YOUR_SITE_KEY');
    xhr.send(JSON.stringify({ sessionKey: sessionKey }));
  }
</script>

Set the trigger to fire on the page URL that confirms a conversion (e.g., /thank-you or /order-confirmation).

Response codes

Code Meaning
200 Session successfully marked as a verified human
400 Missing sessionKey in request body
401 Invalid or missing site key in the Authorization header
404 No session found for the given key

FAQ

What if the session has already been marked?

Calling the endpoint again for an already-verified session is safe and returns a 200. The verification timestamp is not updated.

Does this affect the score retroactively?

The original session score is not changed. The verified label is stored alongside the score and used by the efficacy dashboard to measure scoring accuracy over time. Future scoring improvements are informed by this data.

Is it safe to call from the frontend?

Yes. The site key identifies your site but does not grant access to your dashboard or data. The endpoint only accepts session keys that already exist in your site's data, so a malicious caller cannot create fake sessions.

Where do I find my site key?

In the ClickLens dashboard, go to Settings → Site Settings. Your site key is displayed in the integration section alongside the tracking tag snippet.