Documentation
Documentation (JA)
Documentation (JA)
  • Documentation
  • Products
    • Fanplayr Targeting Portal
    • Fanplayr 360
    • PrivacyID
    • SiteSpeed
  • Features
    • Merchandising
    • Security
    • SMS
    • Web Push Notifications
      • Direct Integration Guide
      • Popup Integration Guide
      • Imaging Sizing Guide
    • Data Residency
  • Fanplayr Targeting
    • E-Commerce Integrations
      • BigCommerce
      • CommerceV3
      • Magento 1
        • Getting Started
        • Configuration
      • Magento 2
      • Miva Merchant
      • PrestaShop
      • Salesforce Commerce Cloud
      • Shopify
      • Volusion
      • VTEX
      • VTEX IO
    • Custom Integration
      • Page tracking
        • Apply to cart
        • Session offers
      • Order tracking
      • Data types
        • CartAction
        • Product
      • Data Layer API
      • Enhanced user identification
        • Manual Integration
      • Segmentation as a service
      • Lazy loading
      • Page caching
      • Tag managers
      • Single page apps
      • Custom data for verticals
        • Travel
    • Pixel Integration
    • ESP Integrations
    • Link Decoration
    • User Management
      • User Identity
      • User Properties
  • Other
    • CSP & Domains
Powered by GitBook
On this page
  • How It Works
  • Example
  • Custom handler
  • Simple handler
  • Handler with a callback

Was this helpful?

  1. Fanplayr Targeting
  2. Custom Integration
  3. Page tracking

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

PreviousPage trackingNextSession offers

Was this helpful?

How It Works

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

    E.g.

  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.

Example

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: 'https://example.com/applyOffer.php?code=%c',
  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` 
    console.log(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
    $.ajax({
      type: 'GET',
      url: '/api/apply-code-to-cart',
      data: {
        code: event.code
      },
      complete: function() {
        // Notify Fanplayr that the handler has finished.
        doneFn();
      }
    });
  }; 
};
https://example.com/applyOffer.php?code=%c
https://example.com/applyOffer.php?code=FREESHIP