Ruby on Rails affiliate tracking with Refficks
Stripe Checkout Sessions your Ruby on Rails app creates, credited to the partner whose link brought the buyer.
What it gives you
- A payment through a Checkout Session your app opens is credited to the partner whose link brought the buyer, straight from the payment in your Stripe account.
- A subscription keeps its partner for every renewal, a refund takes the commission back by itself, and partners' codes synced to Stripe work at the checkout as they are.
What it does not
- A visitor who has not accepted cookies, or whose browser sends Global Privacy Control, has no visitor id to pass on. Their sale can still be credited through the partner's discount code.
- Only Checkout Sessions on a Stripe account connected to Refficks are seen. Payments taken some other way need their own guide.
Steps
1. Put the Refficks script on every page
Paste the snippet into the head of every page, in your app's main layout. It records the partner's click when somebody arrives and keeps their visitor id in a first-party cookie, rk_vid.
2. Pass the visitor to Stripe
In the controller action that creates the Checkout Session, read the rk_vid cookie and give it to Stripe as refficks_visitor, in the session's metadata and, for a subscription, in subscription_data's metadata. Leave the rest of your checkout as it is.
If the code that creates the session runs on another domain than your site, the cookie does not reach it. Send window.refficks.visitorId() from the page with the request instead, and use that.
# Where your controller action creates the session: visitor = cookies[:rk_vid] refficks = visitor.to_s.empty? ? {} : { refficks_visitor: visitor } session = Stripe::Checkout::Session.create({ # ...your line items, mode and return URLs, as now... metadata: refficks, # Only for a subscription: subscription_data: { metadata: refficks }, })3. Make a test purchase
Open your site through any partner's link, copied from their page under Partners, and buy something with Stripe in test mode. The checks on this guide in Refficks turn green as each part is seen. A test payment is never counted as a sale.
Sources
Have an account? Open this guide in Refficks for your own script and the checks that show when it is working. New to Refficks? Create an account.