Docs

Embed Script

One line of code to add RetainQ to any website or app.

Basic Integration

Add this script tag to your site, typically before the closing </body> tag:

<script
  src="https://app.retainq.com/widget.js"
  data-flow="your-flow-slug"
  data-trigger="#BUTTON_ID"
></script>

Attributes

AttributeRequiredDescription
data-flowYesYour flow's unique slug (found in Flow Settings)
data-triggerYesCSS selector of your cancel button (e.g. #cancel-btn, .cancel-subscription)

Identifying Users (Optional)

To skip the email collection step and pre-identify the customer, add this before the widget script:

<script>
  window.RetainQ = {
    user: {
      id: "user_123",        // Your internal user ID
      email: "user@example.com",
      name: "John Doe"       // Optional
    }
  };
</script>

When a user is identified, RetainQ tracks their full cancellation history and calculates a churn risk score automatically.

How It Works

  1. The script loads asynchronously (~4KB, no performance impact)
  2. It attaches a click listener to the element matching your data-trigger selector
  3. When clicked, it opens the retention flow in a modal overlay
  4. If the customer accepts an offer → you get notified (email + webhook)
  5. If they decline → they're redirected to your cancellation URL

Single Page Apps (React, Vue, etc.)

For SPAs where the cancel button might not exist on initial page load, the widget uses a MutationObserver to detect when the trigger element appears in the DOM. No extra configuration needed.

Testing

You can test your flow directly at: https://app.retainq.com/c/your-flow-slug

This hosted URL works without the embed script — useful for previewing before integration.