JS

JavaScript SDK

v1.0.0

The official JavaScript library for Retake. Works with any backend (Node.js, Express, etc) or frontend.

Fast Setup
Type-Safe
Webhooks
Backend Ready

Installation

bash
npm install @retakeapi/js

E-commerce Flow

1. Cart Abandonment

Track when a user keeps adding items. If they leave here, we'll email them their cart.

typescript
// 1. Track Cart Abandonment
await retake.track({
  type: "cart",
  userId: "user_123",
  email: "[email protected]",
  value: 120.50,
  currency: "USD",
  items: [
    { id: "shoe_1", name: "Nike Air", price: 120.50, quantity: 1 }
  ],
  metadata: { url: "/checkout" }
});

2. Proceed to Payment

Track just before redirecting to Stripe/Paddle. This captures the highest intent.

typescript
// 2. Track Checkout Started (e.g. before Stripe redirect)
await retake.track({
  type: "checkout",
  userId: "user_123",
  email: "[email protected]",
  value: 120.50,
  metadata: {
    provider: "stripe",
    session_id: "cs_test_123" 
  }
});

// Redirect to payment provider
window.location.href = stripeCheckoutUrl;

3. Track Conversion

When the user pays, tell Retake immediately so we stop sending emails. Safe to call from client or server.

typescript
// 3. Track Conversion (Payment Success)
// Call this on your success page or webhook handler
await retake.trackConversion({
  userId: "user_123",
  value: 120.50,
  currency: "USD",
  transactionId: "tx_123456"
});

// This immediately cancels any scheduled recovery emails.

SaaS Flow

Pricing Interest

Track when known users check your pricing page.

typescript
// SaaS: Track Pricing Page View
await retake.track({
  type: "pricing",
  userId: "user_456",
  email: "[email protected]",
  value: 0,
  metadata: { 
    plan: "pro_yearly", 
    referrer: "product_hunt" 
  }
});

Upgrade Intent

Track when a user tries to upgrade their plan.

typescript
// SaaS: Track Upgrade Intent
await retake.track({
  type: "upgrade",
  userId: "user_789",
  email: "[email protected]",
  value: 499.00,
  metadata: { 
    from_plan: "starter",
    to_plan: "business"
  }
});

Handling Returning Users

When a user clicks the recovery link, use this to restore their state (cart, plan selection, etc).

typescript
// How to handle returning users
const intent = await retake.getRecoveredIntent();

if (intent) {
  console.log("Welcome back!", intent.customerEmail);
  
  if (intent.type === "cart") {
    // Restore cart items and redirect to checkout
    restoreCartItems(intent.items);
    router.push("/checkout");
  } 
  else if (intent.type === "pricing") {
    // Show them the plan they were looking at
    highlightPlan(intent.metadata.plan);
  }
}

Core Functions

track(options)

The main function. Tracks any event: 'cart', 'checkout', 'pricing', 'upgrade'.

trackConversion(options)

Critical! Call this on payment success to stop recovery emails.