Socket
Socket
Sign inDemoInstall

@socialgouv/matomo-next

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socialgouv/matomo-next - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.3.0](https://github.com/SocialGouv/matomo-next/compare/v1.2.2...v1.3.0) (2022-03-10)
### Features
* **routeChangeComplete events:** set referrerUrl and customUrl on routeChangeStart so it can matomo events can be used early on page load (e.g. in a react useEffect) with the correct values ([#72](https://github.com/SocialGouv/matomo-next/issues/72)) ([52f2bbc](https://github.com/SocialGouv/matomo-next/commit/52f2bbc5bad294d07a8e14315081c289622b6c11))
## [1.2.2](https://github.com/SocialGouv/matomo-next/compare/v1.2.1...v1.2.2) (2021-05-11)

@@ -2,0 +9,0 @@

54

lib/__tests__/matomo.test.js

@@ -46,2 +46,4 @@ "use strict";

var mockRouteChangeComplete;
// eslint-disable-next-line @typescript-eslint/init-declarations
var mockRouteChangeStart;
jest.mock("next/router", function () {

@@ -65,7 +67,17 @@ var query = {};

}
mockRouteChangeComplete(route);
if (_event === "routeChangeStart") {
mockRouteChangeStart(route);
}
else {
mockRouteChangeComplete(route);
}
jest.fn();
},
on: function (_event, cb) {
mockRouteChangeComplete = cb;
if (_event === "routeChangeStart") {
mockRouteChangeStart = cb;
}
else {
mockRouteChangeComplete = cb;
}
},

@@ -111,2 +123,37 @@ },

});
describe("router.routeChangeStart event", function () {
beforeEach(function () {
global._paq = [];
jest.resetAllMocks();
});
test("should setReferrerUrl and setCustomUrl on route change start", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
__1.init({ siteId: "42", url: "YO" });
window._paq = [];
router_1.default.events.emit("routeChangeStart", "/path/to/hello?world");
return [2 /*return*/, new Promise(function (resolve) {
expect(window._paq).toEqual([
["setReferrerUrl", "/"],
["setCustomUrl", "/path/to/hello"],
["deleteCustomVariables", "page"],
]);
resolve();
})];
});
}); });
test("should use previousPath as referer on consecutive route change", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
document.title = "test page 2";
router_1.default.events.emit("routeChangeStart", "/path/to/hello2?world");
return [2 /*return*/, new Promise(function (resolve) {
expect(window._paq).toEqual([
["setReferrerUrl", "/path/to/hello"],
["setCustomUrl", "/path/to/hello2"],
["deleteCustomVariables", "page"],
]);
resolve();
})];
});
}); });
});
describe("router.routeChangeComplete event", function () {

@@ -184,2 +231,5 @@ beforeEach(function () {

});
router_1.default.events.emit("routeChangeStart", "/login.php");
router_1.default.events.emit("routeChangeStart", "/path/to/page.php");
router_1.default.events.emit("routeChangeStart", "/path/to/page.php?token=pouet");
router_1.default.events.emit("routeChangeComplete", "/login.php");

@@ -186,0 +236,0 @@ router_1.default.events.emit("routeChangeComplete", "/path/to/page.php");

28

lib/index.js

@@ -68,11 +68,20 @@ "use strict";

previousPath = location.pathname;
router_1.default.events.on("routeChangeStart", function (path) {
if (isExcludedUrl(path, excludeUrlsPatterns))
return;
// We use only the part of the url without the querystring to ensure piwik is happy
// It seems that piwik doesn't track well page with querystring
var pathname = path.split("?")[0];
if (previousPath) {
push(["setReferrerUrl", "" + previousPath]);
}
push(["setCustomUrl", pathname]);
push(["deleteCustomVariables", "page"]);
previousPath = pathname;
});
router_1.default.events.on("routeChangeComplete", function (path) {
var routeExcludedUrl = isExcludedUrl(path, excludeUrlsPatterns);
if (routeExcludedUrl) {
if (isExcludedUrl(path, excludeUrlsPatterns)) {
console.log("matomo: exclude track " + path);
return;
}
// We use only the part of the url without the querystring to ensure piwik is happy
// It seems that piwik doesn't track well page with querystring
var pathname = path.split("?")[0];
// In order to ensure that the page title had been updated,

@@ -82,10 +91,4 @@ // we delayed pushing the tracking to the next tick.

var q = router_1.default.query.q;
if (previousPath) {
push(["setReferrerUrl", "" + previousPath]);
}
push(["setCustomUrl", pathname]);
push(["setDocumentTitle", document.title]);
push(["deleteCustomVariables", "page"]);
if (startsWith(pathname, "/recherche") ||
startsWith(pathname, "/search")) {
if (startsWith(path, "/recherche") || startsWith(path, "/search")) {
push(["trackSiteSearch", q !== null && q !== void 0 ? q : ""]);

@@ -96,3 +99,2 @@ }

}
previousPath = pathname;
}, 0);

@@ -99,0 +101,0 @@ });

{
"name": "@socialgouv/matomo-next",
"version": "1.2.2",
"version": "1.3.0",
"author": "Fabrique numérique des Ministères Sociaux <dsi-incubateur@sg.social.gouv.fr> (https://www.fabrique.social.gouv.fr)",
"homepage": "https://github.com/SocialGouv/matomo-next#readme",
"devDependencies": {
"@socialgouv/eslint-config-react": "1.70.0",
"@socialgouv/eslint-config-typescript": "^1.70.0",
"@types/jest": "26.0.22",
"eslint": "7.24.0",
"@socialgouv/eslint-config-react": "1.97.3",
"@socialgouv/eslint-config-typescript": "^1.97.3",
"@types/jest": "26.0.24",
"eslint": "7.32.0",
"jest": "26.6.3",
"next": "9.5.5",
"prettier": "2.2.1",
"prettier": "2.4.1",
"react": "16.14.0",
"react-dom": "16.14.0",
"ts-jest": "26.5.5",
"typescript": "3.9.9"
"ts-jest": "26.5.6",
"typescript": "3.9.10"
},

@@ -18,0 +19,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc