-
Notifications
You must be signed in to change notification settings - Fork 25
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
Need example how to use it with NextJS router #47
Comments
+1 Add examples of using with NextJS |
@vvmspace my current realization: _app.tsx (custom _app.tsx) import Router from 'next/router';
import {YMInitializer} from "react-yandex-metrika";
...
Router.events.on('routeChangeComplete', (url: string) => {
// To hit only in production and only on client side (in browser)
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
ym('hit', url);
}
});
class MyApp extends App {
componentDidMount() {
// To hit only in production and only on client side (in browser)
if (typeof window !== 'undefined' && process.env.NODE_ENV === 'production') {
const url = window.location.pathname + window.location.search;
ym('hit', url);
}
...
}
...
render () {
// @ts-ignore
const {Component, pageProps, reduxStore, layoutProps} = this.props;
return (
<>
{process.env.NODE_ENV === 'production' &&
<YMInitializer
accounts={[parseInt(process.env.YM_COUNTER_ID as string)]}
options={{webvisor: true, defer: true}}
version="2"
/>
}
<Provider store={reduxStore}>
<ThemeProvider theme={theme}>
<CssBaseline />
<Layout {...layoutProps}>
<Component {...pageProps} />
</Layout>
</ThemeProvider>
</Provider>
</>
)
}
} |
2021 hooks solution
|
I have an e-commerce website that needs to have SSR for SEO purposes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please give the example how to integrate this library with NextJS routing.
The text was updated successfully, but these errors were encountered: