How-To

How to Setup Snapchat Pixel Tracking on Shopify

Learn how to setup your sitewide pixel tracking with custom events and email variables on your Shopify store.

How to Setup Snapchat Pixel Tracking on Shopify

Snapchat is growing in popularity to try and prospect new audiences which isn’t a big surprise given the potential size in audience compared to Facebook, Instagram, Twitter, and others.

Take a look at this chart put together by MarketingLand that shows the total addressable audience comparison for all pages:

social-audiences-all-ages

So if you are marketing to a younger demographic (under 34 years old) then Snapchat might be a good channel to try for yourself.

But before you can do this, you will need to implement Snapchat event tracking on your Shopify store just like you would with Facebook, Adwords, etc.

I’ll show you how to do this via Google Tag Manager so you are free to update and modify your theme moving forward without having to worry about pixels breaking or being deleted!

Implement Snapchat Pixel on Shopify

Step 1: Create Email Variable on Shopify

This can be done one of two ways:

Option a) If you don’t currently have a custom GTM dataLayer implemented on your store then copy this script at the bottom of your theme.liquid file, just above the closing </body> tag:

<script type="text/javascript">

{% if customer %}
window.dataLayer.push({
VisitorType: "Logged In",
CustomerId: "{{ customer.id }}",
CustomerEmail: "{{ customer.email }}",
});
{% else %}
window.dataLayer.push({
VisitorType: "Guest"
});
{% endif %}
</script>

Then you need to create a variable in Google Tag Manager that looks like this:

customer-email-variable-for-shopify-gtm

Make sure you set this up exactly the way it looks above (case sensitive).

(COMING SOON!) Option b) Implement our GTM App for Shopify which automagically adds the customer email variable (among many others) to your Shopify store

We know how difficult it is to think about all potential dataLayer variables needed in GTM so we’ve built an app to fix this for you! We’re testing with a few stores right now before we release to publish but feel free to chat us if you’re interested in this automated step.

Step 2: Install Snapchat Sitewide Script into GTM Tag

This step requires you to log in to your Snapchat Ads Manager > Go to Snap Pixel > Set Up Pixel

You should see something like this below which you have to click to copy:

snapchat-sitewide-pixel

Then you will need to head over to Google Tag Manager > Tags > Create New Tag > Custom HTML Tag > Paste your script you just copied from Snapchat:

snapchat-sitewide-tag-for-shopify-with-email

You’ll notice the red arrow is pointing to the email variable within the script that you will need to modify and update to be your email variable created in Step 1.

IMPORTANT: When setting your trigger, do not just use the built-in All Pages trigger from GTM. You will need to create a new All Pages trigger that fires on DOM Ready like this:

all pages dom ready pageview

Step 3: Install Snapchat Conversion Pixel via Shopify Thank You Page Scripts

This next step implements the Snapchat Conversion Pixel Event for tracking purchases. You can use the script below to copy into your Shopify Store > Settings > Checkout > Additional Scripts

You will need to update the bolded ID section below to match your own Snapchat pixel ID from your Ad center settings.

<!-- Snapchat conversion -->
<script type='text/javascript'>
(function(win, doc, sdk_url){
if(win.snaptr) return;
var tr=win.snaptr=function(){
tr.handleRequest? tr.handleRequest.apply(tr, arguments):tr.queue.push(arguments);
};
tr.queue = [];
var s='script';
var new_script_section=doc.createElement(s);
new_script_section.async=!0;
new_script_section.src=sdk_url;
var insert_pos=doc.getElementsByTagName(s)[0];
insert_pos.parentNode.insertBefore(new_script_section, insert_pos);
})(window, document, 'https://sc-static.net/scevent.min.js');

snaptr('init', '6b5bc1aa-3fcb-4183-111111111111111111', {'user_email': '{{ checkout.email }}'});

snaptr('track', 'PURCHASE', {'currency': '{{shop.currency}}', 'price': '{{checkout.total_price | money_without_currency}}','transaction_id':'{{checkout.order_id}}'});
</script>

Step 4: Install Snapchat Add to Cart and Initiate Checkout Events via GTM Tags

The last step is optional but will be good for you to track performance higher up in your funnel besides purchases.

We’ll use the Add to Cart event as provided by Snapchat as an example and the same can be applied to Initiate Checkouts as well.

snapchat-add-to-cart-custom-event

  1. First you’ll need to be sure you have a custom trigger in GTM that is for Add to Cart events on your store. If you need help creating this trigger, read my guide on how to create custom triggers in GTM here.
  2. Copy the add to cart event (shown below)
  3. Update the bolded pixel ID with your own pixel ID
<script type='text/javascript'>
(function(win, doc, sdk_url){
if(win.snaptr) return;
var tr=win.snaptr=function(){
tr.handleRequest? tr.handleRequest.apply(tr, arguments):tr.queue.push(arguments);
};
tr.queue = [];
var s='script';
var new_script_section=doc.createElement(s);
new_script_section.async=!0;
new_script_section.src=sdk_url;
var insert_pos=doc.getElementsByTagName(s)[0];
insert_pos.parentNode.insertBefore(new_script_section, insert_pos);
})(window, document, 'https://sc-static.net/scevent.min.js');

snaptr('init','xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',{
'user_email':’{{CustomerEmail}}’
})
snaptr('track','ADD_CART')
</script>

You can copy this step for any other custom event that you want to track. Once you preview and publish your new tags you are good to go!

Your final GTM updates ready to publish should look something like this:

snapchat-gtm-tags-triggers-for-shopify

Happy Snapchatting marketing 🙂

If you found this helpful then please sign up for our emails where we share more helpful guides for Shopify and making $$ with your store!

More Marketing & Analytics Tips

Join our email where we share our best marketing and analytics tips.

We respect your inbox.


Brad Redding

Brad, co-founder of Elevar, has lived in eCommerce for over 12 years. He's helped design, build, and optimize over 100 websites in his career. From new retail startups to well-known brands like Le Creuset, Signature Hardware, Rebecca Minkoff, Char-Broil and more, he specializes in data analytics and conversion optimization to help achieve business goals.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Articles

Talk with Us

Please complete the form to request a demo, discuss our solutions, or to just say hi!



Some of our clients