OneTrial with Django
- Snippet on the signup page:
html<script src="https://onetrial.dev/v1.js" data-key="YOUR_PUBLIC_KEY" async></script>
- Send the token with the form:
js// Signup form (browser): include the token in your POSTconst token = await OneTrial.getToken(); // window.OneTrial is set by the snippetOneTrial.markSubmit(); // records time-to-submitformData.append('visitorToken', token);
- Decide in the signup view:
python# views.pydef 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, requestsr = 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 webhookcreate_trial(user_id)return JsonResponse({"ok": True})
- Env:
ONETRIAL_API_KEY=ot_test_...(server only). Test keys hit the same engine; switch toot_live_when you go live. - Verify:
GET /api/v1/integration/statusreturns a checklist. Shadow mode is on until you flip it.