Add Rewardful to your website
The final step is to add Rewardful to your website so that we can track visits, leads, and conversions.
These instructions have been prepared for Sticky Speed.
These instructions are for the
server-side version of Stripe Checkout,
which runs on your server using the
Checkout Session API.
Please see
these instructions
if you're using the client-side version of Stripe Checkout, which uses JavaScript in the web browser.
Overview
Rewardful integrates with Stripe Checkout by passing the unique click ID (i.e. referral ID) to Stripe as the
client_reference_id
parameter when redirecting to checkout. It's important to note that
Stripe Checkout will raise an error if client_reference_id
is set to a blank value,
so it should only be sent when present.
Step 1: Install JavaScript Snippet
Paste the following JavaScript snippet into the
<head>
tag:
<script>(function(w,r){w._rwq=r;w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}})(window,'rewardful');</script>
<script async src='https://r.wdfl.co/rw.js' data-rewardful='80669a'></script>
Copy
It must appear on every page of your application
and marketing website.
Step 2: Pass the referral ID from the browser to your server
When a visitor arrives on your website through an affiliate link, Rewardful creates a unique referral ID to represent that visitor.
This value (a UUID string) must be passed from the browser to your server so it can be included in the Stripe API call that initiates a Checkout session.
You can use our
JavaScript API
to send the referral ID (
Rewardful.referral
) from the web browser to your server via AJAX, or insert
Rewardful's hidden input.
within a form that's submitted to your server.
Step 3: Pass the referral ID to Stripe
Note:
These examples use Ruby as the programming language, but the same concepts apply regardless of the
erver-side language you're using.
Now that the referral ID has been passed to your server, we will send it as the
client_reference_id
parameter to the
create Checkout Session API
endpoint.
If you're using the checkout only for credit card capture or for a one-time sale (mode
parameter is set to setup
or payment
) then make sure to
also pass a value of 'always'
for customer_creation
. Otherwise,
we won't be able to associate a referral on Rewardful with a customer on Stripe. (Merchants using
checkout in subscription
mode can ignore this setting.)
checkout_params = {
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
payment_method_types: ['card'],
line_items: [{ price: 'price_ABCD1234', quantity: 1 }],
mode: 'payment',
customer_creation: 'always'
}
if params[:referral]
checkout_params[:client_reference_id] = params[:referral]
end
Stripe::Checkout::Session.create(checkout_params)
Copy
Note that
client_reference_id
is being assigned the value
params[:referral]
(sent from the browser) if it's present. Please see the
Stripe documentation
on
client_reference_id
for more details.