1

I want to use Matomo (Piwik) inside my website. But for some reason the Matomo code does not work properbly when using babelify.

This is the pure matomo.js file:

var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
  var u="//monitor.example.com/";
  _paq.push(['setTrackerUrl', u+'piwik.php']);
  _paq.push(['setSiteId', '2']);
  var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  console.log(s);
  g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

And after babelify:

(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */


_paq.push(['trackPageView']);

_paq.push(['enableLinkTracking']);

(function () {
  var u = "//monitor.example.com/";

  _paq.push(['setTrackerUrl', u + 'piwik.php']);

  _paq.push(['setSiteId', '2']);

  var d = document,
      g = d.createElement('script'),
      s = d.getElementsByTagName('script')[0];
  console.log(s);
  g.type = 'text/javascript';
  g.async = true;
  g.defer = true;
  g.src = u + 'piwik.js';
  s.parentNode.insertBefore(g, s);
})();

},{}]},{},[1]);

Using the babelify file ends up in not setting cookies as expected. If I use the vanilla matomo.js file, the cookies are set as expected.

tomole
  • 927
  • 3
  • 12
  • 35
  • Are you sure the issue is because of this transformation and not another step in your workflow? The cookies aren't set by this code, but by the loaded `piwik.js`. – lw1.at Jan 21 '19 at 21:08

0 Answers0