Goals
A goal is any step you want to count: a sign-up, a click on "Book a call", a visitor who reads your pricing. Goals show on the dashboard and in funnels.
In your HTML (no JavaScript)
<button data-bh-goal="start_trial" data-bh-goal-plan="pro">Start trial</button>
<section data-bh-scroll="read_pricing" data-bh-scroll-threshold="0.5" data-bh-scroll-delay="1000"> ... </section> data-bh-goal="<name>": a goal when someone clicks it (or presses Enter or Space on it). Everydata-bh-goal-<param>attribute becomes a parameter, with dashes turned into underscores.data-bh-scroll="<name>": a goal when the element is on screen.data-bh-scroll-thresholdis how much must show (0 to 1, default 0.5).data-bh-scroll-delayis how many milliseconds it must stay (default 0).
From JavaScript
blazehive("signup", { plan: "pro" }); // a goal with up to 10 parameters
blazehive("identify", { user_id: "user_42", name: "Ana", email: "[email protected]" }); To call it before the visitor code has loaded, add this line first. Calls are then replayed when it loads:
window.blazehive = window.blazehive || function () { (window.blazehive.q = window.blazehive.q || []).push(arguments); }; - Goal names are cut to 64 characters.
- Parameter names use
a-z,0-9,_and-, up to 64 characters. Values are cut to 255 characters. - More than 10 parameters, or one bad name, drops the whole call with a console error.
identifyneedsuser_id. A name and email you send show next to that visitor in your dashboard.- Payments are never sent from the browser. They come from Stripe or from your server.
From your server
For a step that happens later, like an upgrade, send it from your server with an API key:
curl -X POST "https://data.blazehive.io/api/v1/goals" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"visitorId":"VISITOR_ID","name":"upgraded","metadata":{"plan":"pro"}}' Connect Stripe
In Analytics settings, Revenue:
-
Step 1
Open Stripe and make a restricted key
On Stripe's API keys page, click Create restricted key.
-
Step 2
Give it these four permissions
- Webhook Endpoints: Write
- Invoices: Read
- Checkout Sessions: Read
- Charges: Read
Everything else stays None.
-
Step 3
Paste the key
It starts with
rk_live_. We read your payments, and we ask Stripe to tell us about each new one. The key is never shown again, not even in part.
| If you paste | What happens |
|---|---|
A key that starts with pk_ | This is a publishable key. Make a restricted key instead. |
A key that starts with sk_ | Refused on purpose. It can do everything in your Stripe account. Make a restricted key instead. |
A secret that starts with whsec_ | Paste it under Set it up by hand instead. |
A key that starts with rk_test_ | Only test payments will show. The app asks you to confirm. |
Past payments
After you connect, pick how far back to bring payments in: Last 30 days, Last 3 months, Last year, Last 2 years. Running it again adds nothing twice.
Set it up by hand
Under Set it up by hand, the app shows your webhook address
(https://data.blazehive.io/api/stripe/webhook/<your site id>). In Stripe, open Developers, then Webhooks,
add an endpoint with that address and these events, then paste its signing secret in the app. Past payments cannot
be imported this way.
checkout.session.completed
checkout.session.async_payment_succeeded
invoice.paid
invoice_payment.paid
charge.refunded
customer.subscription.created
customer.subscription.deleted Disconnect. New payments stop showing. Payments you already have stay.
Which visit made the sale
Each payment is credited to the visitor's first visit: where they came from, their campaign and country. We find the visitor in this order. The first that matches wins.
| Order | Where the visitor comes from |
|---|---|
| 1 | Stripe metadata bh_visitor_id (and bh_session_id) on the Checkout Session, the Subscription or the invoice. |
| 2 | The Checkout Session's client_reference_id, when it has our bhv_ shape. Our visitor code sets it on Payment Links, Buy Buttons and Pricing Tables. |
| 3 | The Stripe customer, when an earlier payment of that customer named the visitor. This is how renewals are credited. |
| 4 | Nothing. The payment still counts, as Direct. |
| How you sell | Credited with no code? |
|---|---|
| Stripe Payment Links on buy.stripe.com | Yes. The visitor code adds client_reference_id to the link when it is clicked. Every other part of the link stays the same. |
| Stripe Buy Buttons and Pricing Tables | Yes. The visitor code adds the client-reference-id attribute to <stripe-buy-button> and <stripe-pricing-table>. |
| Renewals of a subscription | Yes. They follow the customer's first credited payment. |
| Your own Stripe Checkout | Add two lines. See below. |
| Payment Links on your own domain, Stripe links inside a frame, links in emails, invoices sent from Stripe | No. They count as Direct. |
| Sites in no-cookie mode, and visitors who opted out | No. They count as Direct. |
The value we set looks like this (at most 138 characters, inside Stripe's rules):
bhv_7f3c2a1e-5b6d-4c8e-9a0b-1c2d3e4f5a6b__bhs_s0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d
A link or element that already has a client_reference_id of your own is never changed. To turn this
off, add data-stripe-links="false" to the visitor code tag.
Your own checkout
Where your server creates the Stripe Checkout Session, pass the two cookies our visitor code sets. Metadata wins over client_reference_id.
// Where your server creates the Stripe Checkout Session.
// The two cookies are set by our visitor code on your site.
const visit = {
bh_visitor_id: req.cookies.bh_visitor_id,
bh_session_id: req.cookies.bh_session_id,
};
const session = await stripe.checkout.sessions.create({
// ...your line items, mode, URLs
metadata: visit,
// Only with mode: "subscription", so renewals are credited too:
subscription_data: { metadata: visit },
}); Other payment tools
Paddle, Lemon Squeezy or your own billing: send each payment from your server with
POST /api/v1/payments. To credit the visit, many
checkouts take one free-text reference that comes back with the order. Put this value in it:
const v = document.cookie.match(/(?:^|; )bh_visitor_id=([^;]+)/)?.[1];
const s = document.cookie.match(/(?:^|; )bh_session_id=([^;]+)/)?.[1];
const reference = v ? `bhv_${v}` + (s ? `__bhs_${s}` : "") : null; // letters, digits, dashes and underscores Send it back as visitorId when the order is paid. Send renewals with the same customerId and no visitorId.
How money is counted
- Only money actually collected counts. Trials, zero invoices and unpaid invoices add nothing.
- A refund lowers the payment. A full refund removes it from revenue.
- A payment in another currency is converted to your site's currency at the rate of the payment day. Changing your currency later does not convert payments you already have.
Stripe also adds these goals:
| Goal | When |
|---|---|
payment | Every payment. |
trial_started | A subscription started with a trial. |
subscription_started | A subscription started and is active. |
subscription_ended | A subscription ended. |