Page tracking

Tracks user behavior as they move through pages on your site.

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',
      searchQuery: ''
    },
    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>

Configuration

version

  • Type: integer

  • Scope: All pages

  • Required

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

accountKey

  • Type: string

  • Scope: All pages

  • Required

Unique string used identify your account with the Fanplayr platform.

storeDomain

  • Type: string

  • Scope: All pages

  • Default: Value of window.location.hostname

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

connect

  • Type: object

  • Scope: All pages

  • Default: undefined

The path to the server-side page for Enhanced User Identification.

applyToCartUrl

  • Type: string

  • Scope: All pages

  • Default: undefined

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

  • Type: string

  • Scope: All pages

  • Default: undefined

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

allowOfferPrompt

  • Type: boolean | function

  • Scope: All pages

  • Default: undefined

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

  • Type: integer

  • Scope: All pages

  • Required

The number of unique products currently added to the cart.

numItems

  • Type: integer

  • Scope: All pages

  • Required

The total quantity of all items added to the cart.

gross

  • Type: float

  • Scope: All pages

  • Required

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

  • Type: float

  • Scope: All pages

  • Required

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

  • Type: float

  • Scope: All pages

  • Required

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

  • Type: string

  • Scope: All pages

  • Required

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

pageType

  • Type: string

  • Scope: All pages

  • Required

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

  • Type: string

  • Scope: All pages

  • Default: "USD"

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

brands

  • Type: string[]

  • Scope: Home, Product and Category pages

An array of brand names associated with the current page.

categories

  • Type: string[]

  • Scope: Product and Category pages

  • Required

An array of category names associated with the current page.

categoryId

  • Type: string

  • Scope: Product and Category pages

  • Deprecated. Use categories instead.

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

categoryName

  • Type: string

  • Scope: Product and Category pages

  • Deprecated. Use categories instead.

Name of the current category if available.

productId

  • Type: string

  • Scope: Product pages

  • Required

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 Product.id for more information.

productSku

  • Type: string

  • Scope: Product pages

  • Required

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

productPrice

  • Type: float

  • Scope: Product pages

  • Required

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

  • Type: string

  • Scope: Product pages

  • Required

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

productUrl

  • Type: string

  • Scope: Product pages

  • Required

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

  • Type: string

  • Scope: Product pages

  • Required

URL of the product image.

customerEmail

  • Type: string

  • Scope: All pages

The email address of the current user.

customerId

  • Type: string

  • Scope: All pages

  • Deprecated

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

This property is deprecated and has been superseded by the User Identity feature. Specify a logged-in user's identifier using the special $user identity.

products

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

See the Product object for more details on values to store in this array.

cartAction

  • Scope: All pages

  • Default: "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.

identities

An identity map object which allows you to associate other user identities with Fanplayr's own user identifier in order to improve the signals which Fanplayr users to identify returning users. See the Identity Management documentation for more details.

searchQuery

  • Type: string

  • Scope: Search pages

Used to capture any search terms or query the user has entered on a Search result page on the website. See the pageType property.

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
    ...
  }
});

Last updated