User Behavior Tracking

Fanplayr can easily track the user behavior across your site, which along with our user behavior tracking, can be used to analyze your store and identify opportunities to improve your business through targeting non-converting customer profiles.

Tracking Code Template

The following Javascript code template must be placed all pages, except the order confirmation page.

<script>
(function(d, w, s) {
  var f = w.fanplayr = w.fanplayr || { _i:[] };
  f._i.push({
    version: 3,
    accountKey: '',
    applyToCartUrl: '',
    sessionOfferUrl: '',
    data: {
      lineItemCount: 0,
      numItems: 0,
      gross: 0.00,
      total: 0.00,
      discount: 0.00,
      discountCode: '',
      pageType: '',
      categoryId: '',
      categoryName: '',
      productId: '',
      productName: '',
      productSku: '',
      productPrice: 0.00,
      productUrl: '',
      productImage: '',
      currency: '',
      products : [
        {
          id: '',
          sku: '',
          price: 0.00,
          qty: 1,
          name: ''
        }
      ],
      cartAction: 'override'
    },
    custom_data: {
      // ...
    }
  });
  var js = d.createElement(s);
  var fjs = d.getElementsByTagName(s)[0];
  js.async = true;
  js.src = 'https://cdn.fanplayr.com/client/production/loader.js';
  fjs.parentNode.insertBefore(js, fjs);
})(document, window, 'script');
</script>

Config

version Integer

Required. Constant. Must be set to 3.

Tracking format version identifier used by the Fanplayr platform. Must be set to 3.

accountKey String

Required.

Unique string used identify your account with the Fanplayr platform.

storeDomain String

Defaults to the value of window.location.hostname.

Can be used to optionally override the domain that Fanplayr associates with the session.

applyToCartUrl String

If provided, this will allow Fanplayr widgets to apply offer codes directly to your cart. This can increase the ease at which your visitors convert into paying customers. See the Apply to Cart section for more details.

sessionOfferUrl String

If provided, this will allow Fanplayr to use the Session Offer security method. See the Session Offers section for more details.

allowOfferPrompt Boolean | Function

Offer Flyout widgets can be configured to prompt users to apply any collected offers to the cart by forcing open the wallet when no offer has been applied. By default, this feature is only triggered on the cart page.

This option used to enabled or disable this feature for the current page (regardless of page type). If a function is provided, the return value is used.

Possible Values

  • true - Allows offer prompts on current page, including non-cart pages.
  • false - Disables offer prompts on current page.

Regardless of the value, the offer prompt feature will only be used if there is no offer currently applied to the cart.

Tracking Variables

The following variables must be provided in the data object. Example:

{
  version: 3,
  accountKey: '7e43c8cddccade2b95ee5286ba89758a',
  data: {
    lineItemCount: 2,
    numItems: 2,
    gross: 89.90,
    total: 79.90,
    discount: 10.00
  }
}

lineItemCount Integer

Required, applies to ALL pages.

The number of unique products currently added to the cart.

numItems Integer

Required, applies to ALL pages.

The total quantity of all items added to the cart.

gross Float

Required, applies to ALL pages.

The total value (in the specified currency) of the items currently in cart. More specifically, the sum total of the items in the cart before discounts, shipping and taxes.

total Float

Required, applies to ALL pages.

This is the total value (in the specified currency) of the items currently in cart. More specifically, the sum total of the items in the cart before shipping and taxes, but after discounts.

discount Float

Required, applies to ALL pages.

This is the total value of discounts applied to the cart. This means discounts such as free shipping or shipping discounts should not change this value.

discountCode String

Required, applies to ALL pages.

The discount code applied to the cart (if any). If there are multiple discount codes applied, separated them with commas.

pageType String

Required, applies to ALL pages.

The type of the current page. Valid values are:

  • home – The homepage.
  • prod – A product page.
  • cat – A category page or list of products.
  • srch – A specific search page, or search results page.
  • cart – The shopping cart page.
  • checkout - A page in the checkout flow, but not the order confirmation page.
  • blog - A blog page.
  • page – Any other page. E.g. 'About', 'Contact' etc.

currency String

Applies to ALL pages. Defaults to "USD".

The ISO 4217 currency code of the product and cart values being tracked.

categoryId String

Applies to Product and Category pages.

ID of the current category. This should be specified on category and product pages.

categoryName String

Applies to Product and Category pages.

Name of the current category if available.

productId String

Applies to Product pages.

A single, unique product identifier. Used to differentiate products in the cart or order.

This is also used to link individual product page views to product added to the cart. See the Product ID property for Product Tracking.

productSku String

Applies to Product pages.

The product SKU. This may be the same as productId, but is also made available as a segmentation option.

productPrice Float

Applies to Product pages.

The unit price of the product visible to the user.

For carts that implement a base price and a discounted/sale price, use the discounted price if it is the price shown to users when they add the product to the cart.

productName String

Applies to Product pages.

The name of the product currently being browsed. E.g. "Red Shoes".

productUrl String

Applies to Product pages.

URL of the page that displays full details of the product. This property should be used when tracking a product "quickview" so that the actual URL of the product page is captured correctly.

productImage String

Applies to Product pages.

URL of the product image.

customerEmail String

Applies to ALL pages.

The email address of the current user.

customerId String

Applies to ALL pages.

This is an identifier of the user that is internal to your site. This is used to track new and repeat users.

products Array<Object>|String

Applies to ALL pages.

An array of objects (or JSON) representing the products that are currently in the shopping cart.

See Product Tracking for more details.

cartAction String

Applies to ALL pages. Defaults to "override".

This is a special variable that determines how Fanplayr will treat cart-related data for the current tracking call. It can be used to carry forward cart details (total value in cart, products in cart etc) from the previous page view if they are unavailable for the current tracking call.

See Cart Actions for more details.

Custom Data

If required, Fanplayr is able to capture custom data while tracking user behavior on your site. This data can be used for segmenting on data not already supported natively by Fanplayr.

An example of use would be passing in the “logged in” status of a user, internal segmentation information or which is the current store (for example using Magento Enterprise).

To use this feature please contact Fanplayr so we can help you set it up.

{
  accountKey: '7e43c8cddccade2b95ee5286ba89758a',
  // ...
  custom_data: {
    is_logged_in: '1',
    internal_segment: 'general_user',
    store: 'french',
  }
}

Example

The following example could be used to track:

  • A user who is currently browsing the "Red Shoes" product page
  • With two items already added to their cart:
    • Two cups worth $10 each
    • One t-shirt worth $45
  • A coupon code, "WINTER5", applying a $5 discount to the cart
<script>
(function(d, w, s) {
  var f = w.fanplayr = w.fanplayr || { _i:[] };
  f._i.push({
    version: 3,
    accountKey: '7e43c8cddccade2b95ee5286ba89758a',
    data: {
      lineItemCount: 2,
      numItems: 3,
      gross: 65.00,
      total: 60.00,
      discount: 5.00,
      couponCode: 'WINTER5',
      pageType: 'prod',
      categoryId: '45',
      categoryName: 'Women\'s Shoes',
      productId: 'WRS001',
      productName: 'Red Shoes',
      productSku: 'WRS001',
      productPrice: 59.00,
      productUrl: 'https://example.com/women/shoes/001.html',
      productImage: 'https://example.com/images/products/WRS001.jpg',
      currency: 'USD',
      products : [
        {
          id: 'cup001',
          price: 10.00,
          qty: 2,
          name: 'Boring Old Cup'
        },
        {
          id: 'tshirt001',
          price: 45.00,
          qty: 1,
          name: 'Really Expensive T-Shirt'
        }
      ]
    }
  });
  var js = d.createElement(s);
  var fjs = d.getElementsByTagName(s)[0];
  js.async = true;
  js.src = 'https://cdn.fanplayr.com/client/production/loader.js';
  fjs.parentNode.insertBefore(js, fjs);
})(document, window, 'script');
</script>

Dynamic Sites

When the above tracking code is implemented correctly, Fanplayr will track pages after they load as a user browses through the website. This is sufficient for most sites, but additional steps may be needed for sites that load content dynamically.

For example, sites that load product details in a popup overlay instead of redirecting the user to a new page, you will need to implement an additional step in order to correctly track product views.

Additional page views can be tracked dynamically after the initial page view has been tracked by Fanplayr by passing the tracking data to the fanplayr.reinitialize() method.

The tracking data follows the same format as detailed above. Keep in mind that all of the required properties must be present.

// This method is available after the fanplayr script has loaded.
fanplayr.reinitialize({
  type: 'st',
  accountKey: '7e43c8cddccade2b95ee5286ba89758a',
  data: {
    pageType: 'prod',
    productId: '56_b2',
    // Many required properties are omitted for brevity
    ...
  }
});

results matching ""

    No results matching ""