[Docs](https://userjourney.dev/docs/) · Install

# Add UserJourney to a Ruby on Rails app

For Rails with ERB layouts, with or without Turbo. `current_user` is Devise's; use your app's own.

## 1. The snippet and identify

In `app/views/layouts/application.html.erb`, in the `<head>`. Your key is on the Setup page of the dashboard. The first identify for someone is their sign-up.

```
<script src="https://userjourney.dev/uj.js" data-key="pk_…" defer></script>
<% if current_user %>
  <script>
    addEventListener("DOMContentLoaded", () =>
      uj.identify(<%= raw current_user.id.to_s.to_json %>, <%= raw({ email: current_user.email, name: current_user.name }.to_json) %>))
  </script>
<% end %>
```

Rails' `to_json` escapes `<`, `>` and `&`, so it's safe inside the script. With Turbo, the snippet stays loaded between visits, counts each one as a page view and remembers who is signed in.

## 2. Sign-out

```
<%= button_to "Sign out", destroy_user_session_path, method: :delete, form: { onsubmit: "window.uj && uj.reset()" } %>
```

## 3. Onboarding steps

Pages under `/onboarding/<step>`, `/setup/<step>`, `/welcome/<step>` or `/get-started/<step>` count as steps by themselves. Steps that happen on the server (an import finishing, a first API call) go through the [server API](https://userjourney.dev/docs/#server):

```
Net::HTTP.post(
  URI("https://userjourney.dev/api/v1/server"),
  { u: user.id.to_s, e: [{ t: "step", n: "first_import" }] }.to_json,
  "Authorization" => "Bearer #{ENV.fetch("USERJOURNEY_SECRET_KEY")}", "Content-Type" => "application/json"
)
```

## Payments

Connect [Stripe](https://userjourney.dev/docs/stripe/) or [Paddle](https://userjourney.dev/docs/paddle/) in the dashboard, and each payment, trial and cancellation lands on the person who made it.

## Check it works

Open your site in a private window: you show up on Traffic within a few seconds. Sign up with a test account and it appears on People, with the visit that brought it. Your own team is left out once you sign in; for your visits before that, open any page once with `?uj=off` ([more](https://userjourney.dev/docs/#leave-out)).

If your app sends a Content Security Policy, add `https://userjourney.dev` to `script-src` and `connect-src`.

[Everything else is in the docs →](https://userjourney.dev/docs/)

## See where your users go

Free for your first 250 users. One script and one line of code.

[Start for free](https://userjourney.dev/app)[Read the quickstart](https://userjourney.dev/docs/)
