OneTrial with Rails

  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 SignupsController#create:
ruby
# app/controllers/signups_controller.rb
def create
user = User.create!(email: params[:email])
visitor_token = params[:visitorToken]
res = Net::HTTP.post(URI("https://onetrial.dev/api/v1/decisions"),
{ visitorToken: visitor_token, email: email, ip: request.remote_ip, userId: user.id }.to_json,
"Authorization" => "Bearer #{ENV.fetch('ONETRIAL_API_KEY')}", "Content-Type" => "application/json")
d = JSON.parse(res.body)
return render_paid_plan if d["decision"] == "deny"
return redirect_to d["challengeUrl"], allow_other_host: true if d["decision"] == "challenge"
create_trial(user)
end
  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.