Next.js High Order Component to integrate Yandex.Metrika on every page change.
Install it
yarn add next-ym
Import it inside your pages/_app.js
;
import Router from "next/router";
import withYM from "next-ym";
Wrap your custom App container with it
// pass your YM code as first argument
export default withYM("XXXXXXXX", Router)(MyApp);
That's it, now when the user access a page it will log a pageview to Yandex.Metrika, each page change after that will also trigger a pageview on Yandex.Metrika.
Note: This module detects if it's running in localhost and do nothing there to avoid polluting your analytics with local data.