ActessiaBook a 30-day pilot
Integration guide

Ruby on Rails

A helper that signs identify(), the tag in the layout, reset on sign-out.

1. The signing helper

Copy actessia_sign_identify from the identify() page into lib/actessia.rb; it is stdlib only. The secret goes in credentials:

bin/rails credentials:edit   # actessia: { identify_secret: "…" }

2. Sign in the layout

<%# app/views/layouts/application.html.erb %>
<% if current_user %>
  <% signed = actessia_sign_identify(Rails.application.credentials.dig(:actessia, :identify_secret),
       { "user_id" => current_user.id.to_s, "email" => current_user.email, "plan" => current_user.plan, "issued_at" => Time.now.to_i }) %>
  <script>window.Actessia=window.Actessia||{q:[]};["identify","track","setContext","escalate","open","close","reset"].forEach(function(m){window.Actessia[m]=function(){window.Actessia.q.push([m,[].slice.call(arguments)])}});
    Actessia.identify(<%= raw signed[:payload].to_json %>, <%= raw signed[:signature].to_json %>);</script>
<% end %>
<script async src="https://cdn.actessia.ai/v1/actessia.js" data-site-key="<%= ENV.fetch('ACTESSIA_SITE_KEY') %>"></script>

issued_at is checked against our clock (five minutes of skew), so the page must be rendered fresh, not cached with the signature in it.

3. Sign out

In the view your sign-out redirects to, or in a small script on the sign-out link:

Actessia.reset();

4. Conversions from the server

Net::HTTP.post(URI("https://api.actessia.ai/v1/webhooks/conversions"),
  { user_id: user.id.to_s, event: { event: "upgrade", event_id: invoice.id, value_cents: invoice.total_cents, currency: "EUR" } }.to_json,
  "Authorization" => "Bearer #{ENV.fetch('ACTESSIA_SERVER_KEY')}", "Content-Type" => "application/json")