Apply to cart

Fanplayr widgets are capable of applying offer codes directly to your store's cart if supported. By supporting this feature, you increase the ease at which your visitors can convert into paying custom

How It Works

  1. You provide Fanplayr with a special applyToCartUrl URL as part of your user tracking implementation.


  2. Offer widgets that use the Apply to Cart feature will redirect the browser to this URL, replacing the %c variable with the offer code to be applied.

  3. Upon navigating to this URL your cart software must:

    1. Apply the specified offer code to the cart.

    2. Redirect the user to the cart page.

    3. Best Practice: If the offer is not successfully applied to the cart, show an informative message to the user explaining why the offer was not applied.


The following example shows how you could configure the User tracking aspect of Fanplayr to support the Apply to Cart feature.

If the user is presented a targeted Free Shipping offer with the code FREESHIP, the widget would navigate the browser to when this feature is activated.

  type: 'st',
  accountKey: '7e43c8cddccade2b95ee5286ba89758a',
  applyToCartUrl: '',
  data: {
    // User tracking data

Custom handler

Sometimes you may not be able to simply hit a URL to apply a coupon. In this case you can supply a function handler to the Fanplayr platform to use when a user clicks the Apply button.

Simple handler

// The `fanplayr_ready` function is called once the main Fanplayr scripts are loaded.
window.fanplayr_ready = function() {
  window.fanplayr.platform.capabilities.applyToCart = function(event) {
    // Do something with `event.code` 

Handler with a callback

// A `doneFn()` callback function can be accepted a second argument.
// This should be called to once your handler has finished its work.
// This allows Fanplayr to prevent the handler from being called multiple times
// and to disable any UI attached to the handler.
window.fanplayr_ready = function(){ 
  window.fanplayr.platform.capabilities.applyToCart = function (event, doneFn) { 
    // `event.code` is the coupon code to apply
      type: 'GET',
      url: '/api/apply-code-to-cart',
      data: {
        code: event.code
      complete: function() {
        // Notify Fanplayr that the handler has finished.

Last updated