Skip to main content

Drupal Affiliate Program Setup with Stripe

Know what must work before you launch

Connect a sitewide Drupal library to a checkout path you can verify

Best fit
Teams evaluating AffiliateBase for a Drupal affiliate workflow.
Checkout handoff
The checkout path must receive the generated AffiliateBase referral ID.
Proof required
Complete one referred checkout and confirm the attributed sale and commission.

Follow the attribution evidence

Illustrative scenario · fictional values

  1. Referred visit

    ?via=partner

    AffiliateBase captures the visit and generates a referral record.

  2. Checkout handoff

    referral ID

    The checkout must carry the generated identifier into Stripe.

  3. Paid event

    $99 paid

    A supported Stripe event confirms the attributed payment.

  4. Commission

    $19.80 due

    An eligible attributed sale creates the commission record.

  5. Payout prep

    Payout ready

    Review the commission and prepare the next step with your payout provider.

This guide is for Drupal merchants building a program for their own customers and partners. Add AffiliateBase as a sitewide browser library on the landing and checkout-start pages; do not rely on an administrator-only page or cached markup that omits the script.

Drupal Commerce and payment modules control checkout. Their use of Stripe does not automatically pass AffiliateBase’s generated referral ID, so module-level compatibility remains unverified until the completed Stripe object contains it.

Use a same-page Stripe Payment Link or a custom Checkout Session you control, then follow the Stripe handoff guide and verification checklist.

Follow these steps to integrate AffiliateBase with your Drupal site:

1

Add the Tracking Script

Add the AffiliateBase tracking script to your Drupal site. You can add it via your theme's html.html.twig template or using a module like "Asset Injector". Use the pinned jsDelivr tracking URL for the latest published AffiliateBase release.
html
<script async src="https://app.affiliatebase.io/track.js" data-account-id="YOUR_ACCOUNT_ID"></script>
2

Add via Theme Template

Alternatively, add the script directly to your Drupal theme's html.html.twig file before the closing tag.
twig
{# In your theme's html.html.twig, before </head> #}
<script>(function(w,r){w._abq=w._abq||[];w[r]=w[r]||function(){(w[r].q=w[r].q||[]).push(arguments)}})(window,'affiliatebase');</script>
<script async src="https://app.affiliatebase.io/track.js" data-account-id='YOUR_ACCOUNT_ID'></script>
3

Use Stripe Payment Links or Buttons (Optional)

If you're using Stripe Payment Links or Buy Buttons on your Drupal site, add the tracking script on the same page so AffiliateBase can pass the generated referral ID.
html
<!-- Keep Stripe checkout elements on the same page as the AffiliateBase script. -->
<a href="https://buy.stripe.com/xxxxx">Buy now</a>

<stripe-pricing-table
  pricing-table-id="prctbl_xxx"
  publishable-key="pk_live_xxx"
></stripe-pricing-table>

<!-- For custom or redirected Stripe-hosted links, opt in explicitly. -->
<a data-affiliatebase href="https://link.payment/xxxxx">Buy now</a>
4

Integrate with Drupal Commerce (Advanced)

For Drupal Commerce, capture the referral ID at checkout and pass it to Stripe.
php
<?php
// modules/custom/affiliatebase/affiliatebase.module
use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function affiliatebase_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // Add to checkout forms
  if (strpos($form_id, 'commerce_checkout') !== FALSE) {
    $form['#attached']['library'][] = 'affiliatebase/tracking';

    // Add hidden field for referral ID
    $form['affiliatebase_referral'] = [
      '#type' => 'hidden',
      '#attributes' => ['id' => 'affiliatebase-referral'],
    ];

    // JavaScript to populate the hidden field
    $form['#attached']['html_head'][] = [
      [
        '#tag' => 'script',
        '#value' => 'document.addEventListener("DOMContentLoaded", function() {
          var field = document.getElementById("affiliatebase-referral");
          if (field && window.AffiliateBase?.referral) {
            field.value = window.AffiliateBase?.referral;
          }
        });',
      ],
      'affiliatebase_checkout',
    ];
  }
}
5

Test Your Integration

Visit your Drupal site with a test affiliate link and verify tracking is working.
javascript
// Visit your site with a test affiliate link:
// Open the exact setup-test link shown in AffiliateBase.

// Open browser console and check:
console.log(window.AffiliateBase?.referral); // Should show a generated referral ID

Why Use AffiliateBase with Drupal?

Drupal can host the referral script; payment compatibility depends on the exact commerce and Stripe path.

Simple Script Installation

Add a single script tag via theme template or Asset Injector module.

Commerce Integration

Drupal Commerce requires a custom or documented handoff that puts the generated referral ID on the Stripe payment path.

Stripe Integration

Track conversions from Stripe Payment Links, Buy Buttons, and checkout.

Enterprise Ready

Scalable solution perfect for enterprise Drupal deployments.

Frequently Asked Questions

Does AffiliateBase work with Drupal Commerce?
Yes! You can use Drupal hooks to capture the referral ID at checkout and pass it to your payment processor.
Do I need a custom module for AffiliateBase?
For basic tracking, no module is needed. Just add the script tag. For advanced Commerce integration, a simple custom module helps.
How do I add the script without editing templates?
Use the Asset Injector module to add custom scripts without modifying theme files.
What tracking parameters does AffiliateBase support?
AffiliateBase automatically detects ?via= URL parameters by default. You can add custom token keys with data-affiliatebase-params.

Related Platform Guides

Ready to Launch Your Drupal Affiliate Program?

Get started with AffiliateBase today and start growing your Drupal site with affiliate marketing.