Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(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

Merged
merged 2 commits into from
Mar 10, 2022

Conversation

carolineBda
Copy link
Collaborator

Inside a next and react app, if we push event to matomo on a useEffect, after a routeChange, the values sent are the old one as currently we set the values on the routeChangeComplete.
This PR allow to set the needed values on the routeChangeStart so they can be used early

…eChangeStart so it can matomo events can be used early on page load (e.g. in a react useEffect) with the correct values
@codecov-commenter
Copy link

Codecov Report

Merging #72 (82f05c1) into master (92b6060) will not change coverage.
The diff coverage is 90.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #72   +/-   ##
=======================================
  Coverage   85.00%   85.00%           
=======================================
  Files           1        1           
  Lines          60       60           
  Branches       16       16           
=======================================
  Hits           51       51           
  Misses          1        1           
  Partials        8        8           
Impacted Files Coverage Δ
src/index.ts 85.00% <90.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92b6060...82f05c1. Read the comment docs.

Copy link

@m-maillot m-maillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top la PR !
J'ai détecté ce que je pense être un bug sur les URLs exclues avec l'envoie d'un event mais le bug était déjà présent avant :)

@@ -80,35 +80,37 @@ export function init({
}
previousPath = location.pathname;

Router.events.on("routeChangeStart", (path: string): void => {
if (isExcludedUrl(path, excludeUrlsPatterns)) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quand le path est à exclure, cela signifie que l'on ne met pas à jour les données de matomo.
Je pense que ce if n'est pas à faire dans ce cas précis. On va avoir un comportement étrange quand on va envoyer un event à motomo car il va se baser sur l'ancienne URL vu que l'on n'aura pas mis à jour les données.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

effctivement. c'était comme ça avant donc j'imagine que ce choix est conscient ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui, cela fait référence aux url qu'on exclue du suivi matomo. Or, là où je trouve la chose tricky, c'est si on passe d'une url exclue à une url non exclue, cela ne settera pas correcment le referrerUrl, non ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ca mettra la derniere url non blacklistée en referrer oui;
ca me parait correct

@@ -77,6 +87,43 @@ describe("push", () => {
});
});

describe("router.routeChangeStart event", () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top les tests 👍 (sans snapshot, la vie est plus folle 🎉 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

franchement ouai 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes c'est niquel ça !

peut-être tester avec la logique d'exclusion d'url aussi pour être sûr que ça ne fasse pas des trucs bizarres

@carolineBda carolineBda marked this pull request as ready for review February 25, 2022 08:20
@@ -80,35 +80,37 @@ export function init({
}
previousPath = location.pathname;

Router.events.on("routeChangeStart", (path: string): void => {
if (isExcludedUrl(path, excludeUrlsPatterns)) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui, cela fait référence aux url qu'on exclue du suivi matomo. Or, là où je trouve la chose tricky, c'est si on passe d'une url exclue à une url non exclue, cela ne settera pas correcment le referrerUrl, non ?

@@ -77,6 +87,43 @@ describe("push", () => {
});
});

describe("router.routeChangeStart event", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes c'est niquel ça !

peut-être tester avec la logique d'exclusion d'url aussi pour être sûr que ça ne fasse pas des trucs bizarres

@revolunet
Copy link
Member

Merci pour les corrections !
Est-ce qu'on pousserait pas ca dans une branche alpha pour tester le package npm ?

@carolineBda
Copy link
Collaborator Author

Merci pour les corrections ! Est-ce qu'on pousserait pas ca dans une branche alpha pour tester le package npm ?

Avec plaisir. Je peux faire ça depuis ma PR ?
Juste pour info on a déjà fait le même changement sur la lib qu'on utilise dans le CDTN et ça fonctionne 👍 https://github.com/SocialGouv/code-du-travail-numerique/pull/4254/files

@i-am-the-slime
Copy link

I'd love for this to get merged and released.

@revolunet
Copy link
Member

lets do this

@revolunet revolunet merged commit 52f2bbc into master Mar 10, 2022
github-actions bot pushed a commit that referenced this pull request Mar 10, 2022
# [1.3.0](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](#72)) ([52f2bbc](52f2bbc))
@github-actions
Copy link

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants