angulartics-facebook-pixel icon indicating copy to clipboard operation
angulartics-facebook-pixel copied to clipboard

Pixel keeps reporting the initial page

Open DamodarSojka opened this issue 8 years ago • 1 comments

When moving across the pages and committing events only the initial page (the page when the fbq was initialised) is reported. angulartics-google-analytics works fine. Version 0.2.0

DamodarSojka avatar Jul 04 '17 11:07 DamodarSojka

Hi @DamodarSojka, Thanks for your report :)

I just looked over fbevent.js scripts, and i found that facebook pixel script caches url of initial landing page internally, and it couldn't updated even browser history updated via history.pushState, history.replaceState!

Currently, There doesn't seems any CLEAN workarounds for this issue, because the origin of this behavior is internal part of facebook pixel tracking script.

If you don't mind quick-and-dirty-and-dangerous solution, Use below code. Below code monkey-patches internal part of pixel script.

      fbq('init', 'YOUR_PIXEL_KEY');

     // ADD BELOW CODE!
     (function () {
      var __pixelPatchTimerId = setInterval(function() {
        if (typeof fbq.getFbeventsModules === 'function' && fbq.getFbeventsModules('SignalsParamList')) {
          clearInterval(__pixelPatchTimerId);
          __pixelPatchTimerId = null;

          var _module = fbq.getFbeventsModules('SignalsParamList');
          var _orgFn = _module.prototype.append;
          _module.prototype.append = function() {
            var args = Array.prototype.slice.call(arguments);

            if (args[0] === 'dl') {
              args[1] = location.href; // force updates location that sending to facebook
            }

            return _orgFn.apply(this, args);
          };
        }
      }, 100);
    })();

mooyoul avatar Jul 04 '17 17:07 mooyoul