Shopify
Shopify provides access to add HTML and JavaScript to your shop’s themes and to add conversion tracking upon a successful checkout. Let’s use that ability to add Kissmetrics tracking to important e-Commerce activity.
Use a Native Shopify Application
A partner is providing a Shopify application to make installation easy. They are providing support specifically for this app - hence the monthly cost.
Get the integration at https://apps.shopify.com/kissmetrics.
Doing It Yourself
Part 1. Place the JavaScript Library in your shop’s theme
- Go to the theme editor at https://myshopify.com/admin/themes.
- Open
theme.liquid
or the layout that is used in all the pages of your shop. - Add your JavaScript snippet to the bottom of the
<head>
of the layout, as shown below. - Remember to use your JavaScript snippet, which contains your unique API key rather than
'foo'
.
Code Template
Part 2. Modify the cart to also include the customer’s anonymous identity
- Still in the theme editor, open
cart.liquid
. - As shown below, add a hidden
<input>
field to the cart form (<form action="/cart">
). This field will pass along the customer’s Kissmetrics anonymous ID as an extra cart attribute. In our example, I’ve placed the input beneath the area for order notes. - Place the custom JavaScript at the bottom of
cart.liquid
. This does the actual work of assigning the identity to the hidden field. - The event to record that the customer
Viewed Cart
is helpful, but optional.
Code Template
Part 3. Record the purchase on the order confirmation page
- Head to https://myshopify.com/admin/settings/payments to modify your checkout settings.
- In the section “Order processing”, under “Additional content & scripts”, paste the sample from below.
- Again, remember to use your JavaScript snippet, which uses your unique API key rather than
'foo'
. - The last 3 lines of JavaScript make sure that the person’s ID stays consistent between your shop’s domain and checkout.shopify.com. It will record the event “Purchased”, and the total cart amount as the “Billing Amount” property.