---
title: "Snagr SDK and HTTP API installation guide"
description: "Install Snagr with a browser script and server HTTP API. Track checkout, signup and trial events, verify identity, and configure recovery flows for any app."
url: https://www.snagr.sh/sdk
source: https://www.snagr.sh/sdk.md
site: Snagr
---
# Snagr SDK and HTTP API installation guide

> Install Snagr's browser script to identify customers, send events and display nudges. Use a secret key on your server to confirm completed actions through /api/v1/batch. A flow follows up when its start event arrives and its finish event does not. No payment-provider migration is needed.

## 1. Get your keys and add the browser script

Create a free account and choose SDK setup. The Developers page provides a publishable key for the browser and lets you create a secret key for your server. Replace YOUR_PUBLISHABLE_KEY below; keep the queue stub before any event calls.

```
<!-- Put this before your app's event handlers -->
<script>
  window.snagr = window.snagr || { _q: [] };
  ["track", "identify", "reset", "onState"].forEach(function (method) {
    window.snagr[method] = function () {
      window.snagr._q.push([method, arguments]);
    };
  });
</script>
<script src="https://www.snagr.sh/sdk.js"
  data-key="YOUR_PUBLISHABLE_KEY" defer></script>
```

## 2. Identify the person and send the start event

On your server, sign the authenticated user's normalized email with your secret key. Pass only the resulting emailHash to your browser session. Then identify the person and track the action that should start a flow. Never expose the secret key in browser code.

```
// On your server, after authenticating the user:
import { createHmac } from "node:crypto";
const emailHash = createHmac("sha256", process.env.SNAGR_SECRET_KEY)
  .update(user.email.trim().toLowerCase()).digest("hex");

// Pass emailHash to your authenticated browser session:
window.snagr.identify({ email: user.email, userId: user.id, emailHash });
window.snagr.track("checkout_started", { url: resumeUrl });
```

## 3. Send the finish event from your server

Send purchase_completed after a verified payment, or onboarding_completed after setup finishes. Revenue is in major currency units, so convert cents before sending it. Use a stable messageId for retry safety. Keep currency consistent with your recovery reporting.

```
// In your server, after verifying the payment webhook:
const response = await fetch("https://www.snagr.sh/api/v1/batch", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.SNAGR_SECRET_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ batch: [{
    type: "track", email: customer.email,
    event: "purchase_completed", messageId: order.id,
    properties: { revenue: order.amount / 100, currency: "USD" },
  }] }),
});
const result = await response.json();
if (!response.ok || !result.results?.every((item) => item.ok)) {
  throw new Error("Snagr event delivery failed");
}
```

## 4. Review a flow and verify the install

In Sequences, choose the checkout, signup or trial recipe. Confirm the start and stop event names, edit the copy, and check the return URL. Send a test to an address you own and check the events in Activity. Activate the flow only after reviewing it.

## Questions

### Can I send events without the browser script?

Yes. Use the server API with a secret key and the person's email. Browser installation is needed for on-site nudges and flags; server events can run email recovery by themselves.

### Why does email verification matter?

A publishable key is visible to visitors. By default, browser events cannot make Snagr send to an arbitrary email. Your server verifies the address through a signed emailHash or a secret-key event. Leave unverified email sending disabled.

### What does an event need?

The batch endpoint accepts identify or track messages. A track message names the event and identifies the person by anonymousId, userId or a server-supplied email. Include messageId for idempotency and a usable url in start-event properties for the follow-up link.

### Can my agent do this setup?

Yes. Follow the agent install guide and connect Snagr's MCP server with a secret key. The agent can inspect events and create inactive flows for your review.

## Pricing

Your first recovered payment is free, with up to 50 recovery emails per month before then. No card needed. After the first payment, Pro is $29/month or $290/year. Snagr takes 0% of recovered revenue.


[SDK guide](/sdk) · [Agent setup](/agents) · [Pricing](/pricing)
