Headstream

Ruby on Rails

Updated 2026-11-02

Setup

Copy your snippet from Project settings, then add it to the <head> of app/views/layouts/application.html.erb:

<head>
  <script
    defer
    src="https://headstream-ingest.super-dream-7005.workers.dev/t.js"
    data-key="YOUR_KEY"
  ></script>
</head>

If you have other layouts, such as a marketing layout, add it there too.

Turbo

Turbo Drive changes pages with the history API, which the script watches. Each visit counts as a pageview, so there's nothing to add.

Content Security Policy

If config/initializers/content_security_policy.rb is active, allow the ingest host:

Rails.application.config.content_security_policy do |policy|
  policy.script_src :self, "https://headstream-ingest.super-dream-7005.workers.dev"
  policy.connect_src :self, "https://headstream-ingest.super-dream-7005.workers.dev"
end

Add these hosts to your existing rules. Don't replace them.

Identify signed-in users

Set a queue before the script tag. The script reads window.headstream.q when it loads:

<% if user_signed_in? %>
  <script>
    window.headstream = { q: [["identify", <%= raw json_escape({ email: current_user.email }.to_json) %>]] };
  </script>
<% end %>

Put it above the Headstream tag. user_signed_in? and current_user come from Devise, so swap in your own helpers if you use something else.

If you store a Stripe customer ID, add stripeCustomerId to that hash. It gives Stripe matching (beta) the most direct link.

Check it works

Deploy and load a page on your production domain. Events from localhost are rejected. See identify people for more.

See which marketing makes money.

Get started free