# Stripe (Other Methods)

If you're using Stripe API, follow [this guide](https://docs.humblytics.com/how-to-track-purchase-events/stripe/stripe-api) instead. If you're using Stripe Payment Links, follow [this guide](https://docs.humblytics.com/how-to-track-purchase-events/stripe/stripe-payment-links) instead. Make sure you've connected your Stripe account to Humblytics first.

Use the JavaScript snippet below to attribute the payment to the correct customer journey:

```javascript
// Attribute the purchase to the logged-in customer
window.Humblytics.trackCustomer(customerEmail);
```

Replace `customerEmail` with the email address associated with the successful payment.

## Example Implementation

The safest place to call `trackCustomer` is directly before or after you capture the payment. In a Stripe Elements checkout flow that might look like this:

```jsx
"use client";

import { useState } from "react";
import {
  useStripe,
  useElements,
  PaymentElement,
} from "@stripe/react-stripe-js";

export default function CheckoutForm({ customerEmail, clientSecret }) {
  const stripe = useStripe();
  const elements = useElements();
  const [isSubmitting, setIsSubmitting] = useState(false);

  const handleSubmit = async (event) => {
    event.preventDefault();
    if (!stripe || !elements) return;

    setIsSubmitting(true);

    // Attribute the revenue right before confirming the payment
    window.Humblytics.trackCustomer(customerEmail);

    const { error } = await stripe.confirmPayment({
      elements,
      clientSecret,
      confirmParams: {
        return_url: `${window.location.origin}/welcome`,
      },
    });

    setIsSubmitting(false);

    if (error) {
      // handle error state
    } else {
      // Optionally confirm again after capture if you redirect instead of using return_url
      // window.Humblytics.trackCustomer(customerEmail);
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <PaymentElement />
      <button type="submit" disabled={!stripe || isSubmitting}>
        Pay
      </button>
    </form>
  );
}
```

## When to Use This Method

* **Third-party payment processors** that use Stripe
* **Stripe Elements implementations**
* **Mobile app payments**
* **Custom checkout flows** not covered by other methods

## Important Notes

* **Works with any payment flow** as long as you have access to the customer's email
* **Privacy-compliant** - cookie-free tracking, no consent banners required

After receiving a successful payment, you should see revenue data in your dashboard (referrer, country, browser, etc.) tied to that customer's profile. If you don't, please contact us at <support@humblytics.com>.

<figure><img src="https://1281224403-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqZMBn2D7F1lV2hgGTS2X%2Fuploads%2Fgit-blob-e86484af08c64b8d405d424db66640486da427c4%2Frevenue-attribution-card%20(5).png?alt=media" alt=""><figcaption></figcaption></figure>

## Key Benefits

| Benefit                     | Detail                                       |
| --------------------------- | -------------------------------------------- |
| **Flexible implementation** | Works with any payment flow                  |
| **Manual control**          | Track payments exactly when you want         |
| **Privacy-compliant**       | Cookie-free tracking, no consent banners     |
| **Split test ready**        | Use revenue as conversion goals in A/B tests |

## Setting Up Split Tests with Revenue Goals

1. **Create a split test** on your main website
2. **Choose Revenue** as your goal type
3. **Set your target revenue amount** or use "Any Revenue" for all purchases
4. **Launch your test** - revenue will be automatically tracked

<figure><img src="https://1281224403-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqZMBn2D7F1lV2hgGTS2X%2Fuploads%2Fgit-blob-03fecd05b7f04beb97bc4db8b0cd83737d35eae1%2FSplit-test-revenue%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

## Troubleshooting

* **No revenue data appearing?** Check that your Stripe account is properly connected
* **Missing attribution?** Verify that you're passing the correct customer email to `trackCustomer`
* **Need help?** Contact <support@humblytics.com> for assistance
