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.

Instructions for Ruby on Rails

Choose a different setup method
Step 1: Install JavaScript Snippet
Paste the following JavaScript snippet into the <head> section of your application.html.erb layout file.
<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: Add the referral data to your signup form
Add data-rewardful to the form that gets submitted when you create a Stripe customer (signup form, upgrade form, etc.). In Rails you can do this by adding data: { rewardful: true } to your call to form_with or form_for:
<%= form_with model: @user, data: { rewardful: true } do |signup_form| %>
  <%= signup_form.text_field :name %>
  <%= signup_form.email_field :email %>

  <%= signup_form.submit "Sign up" %>
<% end %>
Copy
Rewardful will automatically insert a hidden input named referral into the form, which will get submitted to your server along with the rest of this form's data. The value will be a UUID representing the current referral. You'll pass this UUID parameter to Stripe in the next step.
Turbo
If you're using Turbo you'll also need to include the snippet below in you main JavaScript file (application.js). This snippet ensures Rewardful attaches to forms with data-rewardful that get added to the DOM by Turbo as the user browses your website.
document.addEventListener("turbo:load", function() {
  Rewardful.Forms.attach();
});
Copy
Step 3: Add the referral UUID to Stripe Customer metadata
The referral parameter will be submitted with the rest of the form data in Step 2. Add referral to the Stripe Customer's metadata.
# Gather params submitted with <form>
customer_params = {
  email: params[:email],
  source: params[:stripe_token] # Obtained with stripe.js
}

# Add the `referral` parameter from Rewardful to the Stripe customer metadata, if present.
if params[:referral].present?
  customer_params[:metadata] = { referral: params[:referral] }
end

# Create the customer in Stripe.
Stripe::Customer.create(customer_params)
Copy
Adding the referral UUID to the Stripe customer's metadata converts the referral and associates it with the affiliate. Whenever that customer is charged, a commission will be paid to the affiliate according to your campaign rules.
Notes:
  • If you already have a Stripe customer created, simply add the referral metadata by updating the customer.
  • You'll also need to pass the coupon parameter to Stripe if you're using our double-sided incentives feature (coupons) Learn more →
  • Refer to the Stripe API Reference for full documentation on creating and updating customers with Ruby.