OneTrial with Django

  1. Snippet on the signup page:
html
<script src="https://onetrial.dev/v1.js" data-key="YOUR_PUBLIC_KEY" async></script>
  1. Send the token with the form:
js
// Signup form (browser): include the token in your POST
const token = await OneTrial.getToken(); // window.OneTrial is set by the snippet
OneTrial.markSubmit(); // records time-to-submit
formData.append('visitorToken', token);
  1. Decide in the signup view:
python
# views.py
def signup(request):
email = request.POST["email"]; visitor_token = request.POST.get("visitorToken")
ip = request.META.get("HTTP_X_FORWARDED_FOR", request.META["REMOTE_ADDR"]).split(",")[0]
user_id = create_user(email)
import os, requests
r = requests.post("https://onetrial.dev/api/v1/decisions",
headers={"Authorization": f"Bearer {os.environ['ONETRIAL_API_KEY']}"},
json={"visitorToken": visitor_token, "email": email, "ip": ip, "userId": user_id}, timeout=5)
d = r.json()
if d["decision"] == "deny": return paid_plan_or_support()
if d["decision"] == "challenge": return redirect(d["challengeUrl"]) # trial unlocks on the webhook
create_trial(user_id)
return JsonResponse({"ok": True})
  1. Env: ONETRIAL_API_KEY=ot_test_... (server only). Test keys hit the same engine; switch to ot_live_ when you go live.
  2. Verify: GET /api/v1/integration/status returns a checklist. Shadow mode is on until you flip it.