segment-integrations / analytics.js-integration-facebook-pixel

The Facebook Pixel analytics.js integration. https://segment.com/docs/integrations/facebook-pixel
MIT License
8 stars 16 forks source link

add flag to disable automatic pageview tracking #8

Closed hankim813 closed 8 years ago

hankim813 commented 8 years ago

This fixes #5.

This is undocumented use of FB's lib but looking at the code regarding how they handle the automatic pageview tracking, setting disableStatePush to true will prevent their library triggering its own page views -- that should only happen when our .page() call is invoked.

This is FB's logic for automatic pageview tracking:

(function ca() {
      if (j.disablePushState === true)
        return;
      if (!d.pushState || !d.replaceState)
        return;
      var da = function() {
        s = m;
        m = c.href;
        if (m === s)
          return;
        var ea = new v({
          allowDuplicatePageViews: true
        });
        j.trackWithoutValidation.call(ea, 'PageView');
      }
      ;
      h.injectMethod(d, 'pushState', da);
      h.injectMethod(d, 'replaceState', da);
      a.addEventListener('popstate', da, false);
    })();

Also there was an empty #loaded test describe block so I removed that and added some additional tests that checks for proper initialization.

@sperand-io @segment-integrations/core

hankim813 commented 8 years ago

@sperand-io : "LGTM"