1

我想在我的网站中使用 Matomo (Piwik)。但由于某种原因,Matomo 代码在使用babelify.

这是纯matomo.js文件:

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);
})();

之后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]);

使用该babelify文件最终会导致未按预期设置 cookie。如果我使用 vanillamatomo.js文件,cookie 会按预期设置。

4

0 回答 0