How to Install klaviyo.js for Shopify Stores

Last updated at:


If you are concerned with your site's performance and loading speed, you can manually install klaviyo.js in your Shopify theme files. If you manually install the .js, we recommend that you uncheck the option to automatically add Klaviyo's onsite javascript to avoid duplicating the code on your site, adding slowness.


Note that you should only do this if you experience very high web traffic or your site suffers from slow loading time for any other reason. Otherwise, we recommend you install klaviyo.js by checking the box on the Shopify integration settings page.

Because pasting this code requires access to your site's HTML and ecommerce platform, our support team is unable offer hands-on assistance. If you don't have a developer on your team and aren't comfortable adding the code yourself, consider reaching out to a Klaviyo partner for assistance.

Install klaviyo.js in Your Shopify Store

To install klaviyo.js into your Shopify store, copy the snippet of code below, and paste it into your theme.liquid file.

In the script below, be sure to replace 'API_KEY' with your Public API Key from your Klaviyo account.

If you've enabled Customer Accounts for your store, you can add an extra script to identify your customers with the email they use to log in to your store.

Again, be sure to replace 'API_KEY' with your Public API Key from your Klaviyo account. The full script will look like the following:

<script async type="text/javascript"
 var _learnq = _learnq || [];
 if ('{{ }}') {
   _learnq.push(['identify', {
       '$email' : '{{ }}'

After you've updated the code snippet, copy it, and move to the next step.

Next, from your Shopify Admin click Online Store > Themes. From the dropdown click Edit Code.

Search for the theme.liquid file. Click on the file to open it in the editor.
Scroll to the bottom of the file and locate the closing </body> tag. Paste the first code snippet directly before the closing </body> tag. Click Save.

Click Save.

Test Your Klaviyo.js

Switch back to your Klaviyo account. Click the Setup Web Tracking link in the account dropdown.


Enter the URL for your Shopify store into the box. Click Next.

Click the link that is generated. This triggers an Active on Site event in your Klaviyo account.

A green Data Received button confirms that your web tracking is set up correctly. 

Was this article helpful?
113 out of 212 found this helpful