To send an analytics event when someone has played, for example to Facebook, we’ll define a function in our HTML that will track the Facebook lead and then have the SmashPops popup call it. You can follow those steps :

  1. In your Shopify admin, go to Themes, Actions and Edit code.
  2. Edit theme.liquid, add the following code to the <head> and hit Save:
    <script>
    window.trackFBLead = function() {
    fbq(‘track’, ‘Lead’);
    };
    </script>

    For information, the equivalent code for event tracking using Google Analytics would be:
    ga(“send”, {
      “hitType”: “event”,
      “eventCategory”: “engagement”,
      “eventAction”: “spun_wheel”
    });
    And for Google Tag Manager, this would be:
    gtag(“event”, “spun_wheel”, {
      “event_category”: “engagement”
    });

  3. Go back to SmashPops, edit your popup and go to SETTINGS and Javascript.
  4.  Select Call a Javascript function … and check When the user wins a coupon, enter “trackFBLead” in the field and save your popup. From now on, everytime someone successfully submits his email (= wins a coupon), your Facebook pixel will be called.