sensaro

Integrating Stripe

Connect a Stripe restricted key to show revenue on the dashboard. To see which visit produced a payment, pass that visit into checkout as metadata.

Connect a restricted key

In Sensaro, open the site and go to Settings → Revenue.

In Stripe, create a restricted key with read access to:

  • Charges and Refunds
  • PaymentIntents
  • Checkout Sessions
  • Accounts

Paste the key and save. Sensaro checks that it can read those resources, then shows the account’s default currency. Remove the connection from the same page.

Total Revenue is the net of succeeded charges and refunds in that currency. A payment Sensaro cannot attach to a visit still counts in that total.

Attribute a payment to a visit

The snippet has to be on the checkout page. When checkout starts, read the open visit:

const visitorId = sensaro.visitorId();
const sessionId = sensaro.sessionId();

Send both values to your server and set them as metadata on the PaymentIntent or the Checkout Session. Both keys are required. One key without the other does not attribute the charge.

Stripe::PaymentIntent.create(
  amount: 2000,
  currency: "usd",
  metadata: {
    sensaro_visitor_id: visitor_id,
    sensaro_session_id: session_id
  }
)

For Stripe Checkout, set the same keys on the Checkout Session. You do not need to copy them onto payment_intent_data.

Stripe::Checkout::Session.create(
  mode: "payment",
  # line items, success_url, and cancel_url
  metadata: {
    sensaro_visitor_id: visitor_id,
    sensaro_session_id: session_id
  }
)

After the first attributed charge, the dashboard adds a Revenue column to the visit tables, including pages, referrers, campaigns, and goals. Cookie tracking is the better mode for this, because it recognises a returning visitor for 90 days.

A subscription renewal, or any other charge with no visit attached, stays in Total Revenue only.