1.2.1 • Published 3 years ago

@openpolitica/matomo-next v1.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago
  • Basic SPA Matomo setup
  • Will track next/router route changes routeChangeComplete event

Usage

Add the init call in your _app.js :

import React from "react";
import App from "next/app";

import { init } from "@socialgouv/matomo-next";

const MATOMO_URL = process.env.NEXT_PUBLIC_MATOMO_URL;
const MATOMO_SITE_ID = process.env.NEXT_PUBLIC_MATOMO_SITE_ID;

class MyApp extends App {
  componentDidMount() {
    init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID });
  }
  render() {
    const { Component, pageProps } = this.props;
    return <Component {...pageProps} />;
  }
}

export default MyApp;

Will track routes changes by default.

Exclude tracking some routes :

This wont track /login.php or any url containing ?token=.

init({
  url: MATOMO_URL,
  siteId: MATOMO_SITE_ID,
  excludeUrlsPatterns: [/^\/login.php/, /\?token=.+/],
});

Track additionnal events :

import { push } from "@socialgouv/matomo-next";

// track some events
push(["trackEvent", "contact", "click phone"]);

Tests

init
  ✓ should create a js tag and initialize (16 ms)
  ✓ should NOT create events when url is not provided (19 ms)
push
  ✓ should append data to window._paq (2 ms)
router.routeChangeComplete event
  ✓ should trackPageView with correct title on route change (5 ms)
  ✓ should use previousPath as referer on consecutive route change (10 ms)
  ✓ should track route as search in /recherche (1 ms)
  ✓ should track route as search in /search (2 ms)
excludeUrlsPatterns
  ✓ should excluded login.php and token variables (7 ms)
  ✓ should exclude initial page tracking (4 ms)
  ✓ should track initial page if not excluded (3 ms)
abababort-controlleracornacorn-globalsacorn-jsxacorn-walkadjust-sourcemap-loaderagent-baseaggregate-errorajvajv-errorsajv-keywordsally.jsanseransi-escapesansi-regexansi-stylesanymatchaprobaargparsearia-queryarity-narr-diffarr-flattenarr-unionarray-includesarray-unionarray-uniquearray.prototype.flatarray.prototype.flatmapasn1asn1.jsassertassert-plusassign-symbolsast-typesast-types-flowastral-regexasync-eachasynckitatobaws-sign2aws4axe-coreaxobject-querybabel-eslintbabel-plugin-dynamic-import-nodebabel-plugin-istanbulbabel-plugin-jest-hoistbabel-plugin-syntax-jsxbabel-plugin-transform-definebabel-plugin-transform-react-remove-prop-typesbalanced-matchbasebase64-jsbcrypt-pbkdfbig.jsbinary-extensionsbluebirdbn.jsbrace-expansionbracesbrorandbrowser-process-hrtimebrowserify-aesbrowserify-cipherbrowserify-desbrowserify-rsabrowserify-signbrowserify-zlibbrowserslistbs-loggerbserbufferbuffer-frombuffer-xorbuiltin-status-codescacachecache-basecall-bindcallsitescamelcasecaniuse-litecapture-exitcaselesschalkchar-regexchardetchokidarchownrchrome-trace-eventci-infocipher-basecjs-module-lexerclass-utilsclassnamesclean-stackcli-cursorcli-widthcliuicocollect-v8-coveragecollection-visitcolor-convertcolor-namecolorettecombined-streamcommandercommondircomponent-emittercompose-functionconcat-mapconcat-streamconsole-browserifyconstants-browserifycontains-pathconvert-source-mapcopy-concurrentlycopy-descriptorcore-js-compatcore-js-purecore-util-iscreate-ecdhcreate-hashcreate-hmaccross-fetchcross-spawncrypto-browserifycsscss-loadercss.escapecssesccssnano-preset-simplecssnano-simplecssomcssstylecyclistddamerau-levenshteindashdashdata-uri-to-bufferdata-urlsdebugdecamelizedecimal.jsdecode-uri-componentdeep-isdeepmergedefine-propertiesdefine-propertydelayed-streamdes.jsdetect-newlinediff-sequencesdiffie-hellmandir-globdoctrinedom-serializerdomain-browserdomelementtypedomexceptiondomhandlerdomutilsduplexifyecc-jsbnelectron-to-chromiumellipticemitteryemoji-regexemojis-listend-of-streamenhanced-resolveentitieserrnoerror-exes-abstractes-to-primitivees5-extes6-iteratores6-symbolescaladeescape-string-regexpescodegeneslint-config-prettiereslint-import-resolver-nodeeslint-import-resolver-typescripteslint-module-utilseslint-plugin-importeslint-plugin-jesteslint-plugin-jsx-a11yeslint-plugin-prettiereslint-plugin-reacteslint-plugin-react-hookseslint-plugin-simple-import-sorteslint-plugin-sort-keys-fixeslint-scopeeslint-utilseslint-visitor-keysespreeesprimaesqueryesrecurseestraverseesutilsevent-target-shimeventsevp_bytestokeyexec-shexecaexitexpand-bracketsexpectextextendextend-shallowexternal-editorextglobextsprintffast-deep-equalfast-difffast-globfast-json-stable-stringifyfast-levenshteinfastqfb-watchmanfiggy-puddingfiguresfile-entry-cachefill-rangefind-cache-dirfind-upflat-cacheflattedflush-write-streamfor-inforever-agentform-datafragment-cachefrom2fs-minipassfs-write-stream-atomicfs.realpathfunction-bindfunctional-red-black-treegensyncget-caller-fileget-intrinsicget-streamget-valuegetpassglobglob-parentglob-to-regexpglobalsglobbygraceful-fsgrowlyhar-schemahar-validatorhashas-flaghas-symbolshas-valuehas-valueshash-basehash.jshehmac-drbghosted-git-infohtml-encoding-snifferhtml-escaperhtmlparser2http-signaturehttps-browserifyhttps-proxy-agenthuman-signalsiconv-liteicss-utilsieee754iferrignoreimport-freshimport-localimurmurhashindent-stringindexes-ofinfer-ownerinflightinheritsinquirerinternal-slotinvariantip-regexis-accessor-descriptoris-arrayishis-binary-pathis-bufferis-callableis-ciis-core-moduleis-data-descriptoris-date-objectis-descriptoris-dockeris-extendableis-extglobis-fullwidth-code-pointis-generator-fnis-globis-negative-zerois-numberis-plain-objectis-potential-custom-element-nameis-regexis-streamis-stringis-symbolis-typedarrayis-windowsis-wslisarrayisexeisobjectisstreamistanbul-lib-coverageistanbul-lib-instrumentistanbul-lib-reportistanbul-lib-source-mapsistanbul-reportsjest-changed-filesjest-clijest-configjest-diffjest-docblockjest-eachjest-environment-jsdomjest-environment-nodejest-get-typejest-haste-mapjest-jasmine2jest-leak-detectorjest-matcher-utilsjest-message-utiljest-mockjest-pnp-resolverjest-regex-utiljest-resolvejest-resolve-dependenciesjest-runnerjest-runtimejest-serializerjest-snapshotjest-utiljest-validatejest-watcherjest-workerjs-tokensjs-yamljsbnjsdomjsescjson-parse-better-errorsjson-schemajson-schema-traversejson-stable-stringify-without-jsonifyjson-stringify-safejson5jsprimjsx-ast-utilskind-ofkleurklonalanguage-subtag-registrylanguage-tagslevenlevenarylevnlines-and-columnsload-json-fileloader-runnerloader-utilslocate-pathlodashlodash.memoizelodash.sortbyloose-envifylru-cachemake-dirmake-errormakeerrormap-cachemap-visitmd5.jsmemory-fsmerge-streammerge2micromatchmiller-rabinmime-dbmime-typesmimic-fnminimalistic-assertminimalistic-crypto-utilsminimatchminimistminipassminipass-collectminipass-flushminipass-pipelineminizlibmississippimixin-deepmkdirpmove-concurrentlymsmute-streamnanomatchnative-urlnatural-compareneo-asyncnext-ticknice-trynode-fetchnode-html-parsernode-int64node-libs-browsernode-modules-regexpnode-notifiernode-releasesnormalize-html-whitespacenormalize-package-datanormalize-pathnpm-run-pathnwsapioauth-signobject-assignobject-copyobject-inspectobject-keysobject-pathobject-visitobject.assignobject.entriesobject.fromentriesobject.pickobject.valuesonceonetimeoptionatoros-browserifyos-tmpdirp-each-seriesp-finallyp-limitp-locatep-mapp-trypakoparallel-transformparent-moduleparse-asn1parse-jsonparse5pascalcasepath-browserifypath-dirnamepath-existspath-is-absolutepath-keypath-parsepath-typepbkdf2performance-nowpicomatchpifypiratespkg-dirplatformpnp-webpack-pluginposix-character-classespostcsspostcss-modules-extract-importspostcss-modules-local-by-defaultpostcss-modules-scopepostcss-modules-valuespostcss-safe-parserpostcss-selector-parserpostcss-value-parserprelude-lsprettier-linter-helperspretty-formatprivateprocessprocess-nextick-argsprogresspromise-inflightpromptsprop-typesprrpslpublic-encryptpumppumpifypunycodeqsquerystringquerystring-es3randombytesrandomfillreact-isreact-refreshread-pkgread-pkg-upreadable-streamreaddirpregenerateregenerate-unicode-propertiesregenerator-runtimeregenerator-transformregex-notregex-parserregexp.prototype.flagsregexppregexpu-coreregjsgenregjsparserremove-trailing-separatorrepeat-elementrepeat-stringrequestrequest-promise-corerequest-promise-nativerequire-directoryrequire-main-filenamerequireindexresolveresolve-cwdresolve-fromresolve-urlresolve-url-loaderrestore-cursorretreusifyreworkrework-visitrimrafripemd160rsvprun-asyncrun-parallelrun-queuerxjssafe-buffersafe-regexsafer-buffersanesass-loadersaxesschedulerschema-utilssemverserialize-javascriptset-blockingset-valuesetimmediatesha.jsshebang-commandshebang-regexshell-quoteshellwordsside-channelsignal-exitsisteransislashslice-ansisnapdragonsnapdragon-nodesnapdragon-utilsource-list-mapsource-mapsource-map-resolvesource-map-supportsource-map-urlspdx-correctspdx-exceptionsspdx-expression-parsespdx-license-idssplit-stringsprintf-jssshpkssristack-utilsstacktrace-parserstatic-extendstealthy-requirestream-browserifystream-eachstream-httpstream-shiftstring_decoderstring-hashstring-lengthstring-widthstring.prototype.matchallstring.prototype.trimendstring.prototype.trimleftstring.prototype.trimrightstring.prototype.trimstartstrip-ansistrip-bomstrip-eofstrip-final-newlinestrip-json-commentsstyle-loaderstyled-jsxstylisstylis-rule-sheetsupports-colorsupports-hyperlinkssymbol-treetabletapabletarterminal-linkterserterser-webpack-plugintest-excludetext-tablethroatthroughthrough2timers-browserifytmptmplto-arraybufferto-fast-propertiesto-object-pathto-regexto-regex-rangetough-cookietr46traversets-pnptsconfig-pathstslibtsutilstty-browserifytunnel-agenttweetnacltypetype-checktype-detecttype-festtypedarraytypedarray-to-bufferunicode-canonical-property-names-ecmascriptunicode-match-property-ecmascriptunicode-match-property-value-ecmascriptunicode-property-aliases-ecmascriptunion-valueuniqunique-filenameunique-slugunset-valueupathuri-jsurixurluseuse-subscriptionutilutil-deprecateuuidv8-compile-cachev8-to-istanbulvalidate-npm-package-licenseverrorvm-browserifyw3c-hr-timew3c-xmlserializerwalkerwatchpackwatchpack-chokidar2web-vitalswebidl-conversionswebpackwebpack-sourceswhatwg-encodingwhatwg-mimetypewhatwg-urlwhichwhich-moduleword-wrapworker-farmwrap-ansiwrappywritewrite-file-atomicwsxml-name-validatorxmlcharsxtendy18nyallistyargsyargs-parser
1.2.1

3 years ago