Link

JavaScript Customer API

Customer Fields provides a robust set of tools available at your disposal that use data columns.

Our JavaScript API can:

  • Register customers
  • Mutate data of logged in customers
  • Manage customer tags
  • Emit customer events for tracking purposes

Getting started

Ensure you have installed a form on the theme you’re working with. We recommend creating a form called something like: “Custom development”, then installing it with only the “Other location” box ticked so our snippet and assets get added.

Add this to the <head> inside your layout/theme.liquid:

{% render 'customer-fields', customer_api: true, version: '<Version number>' %}

This will inject customer data on the page, as well as a <script> that includes our lightweight API for your usage.

Our snippet will add a helper function to the window that you can use to ensure that CF.customer will always be available:

// Add the following after including API
CF.customerReady(function() {
  // CF.customer is reliably available for use here!
});

Since our script is loading asynchronously, it isn’t available for use immediately. For this exact reason our script will emit a cf:customer_ready event when it is. CF.customerReady waits for this event if CF.customer isn’t already present, then fires the callback passed to it.


Next up: Customer data


Table of contents