
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
@jitsu/nextjs
Advanced tools
Jitsu JavaScript SDK for NextJS (more at http://jitsu.com/docs/js-sdk)
This package is a wrapper around @jitsu/sdk-js
, with added functionality related to NextJS.
With NextJS there're several ways on how to add Jitsu tracking
First, create or update your _app.js
following this code
import { createClient, JitsuProvider } from "@jitsu/nextjs";
// initialize Jitsu client
const jitsuClient = createClient({
tracking_host: "__JITSU_HOST__",
key: "__API_KET__",
// See Jitsu SDK parameters section for more options
});
// wrap our app with Jitsu provider
function MyApp({Component, pageProps}) {
return <JitsuProvider client={jitsuClient}>
<Component {...pageProps} />
</JitsuProvider>
}
export default MyApp
See parameters list for createClient()
call.
After jitsu client and provider are configured you will be able to use useJitsu
hook in your components
import { useJitsu } from "@jitsu/nextjs";
const Main = () => {
const {id, trackPageView, track} = useJitsu(); // import methods from useJitsu hook
useEffect(() => {
id({id: '__USER_ID__', email: '__USER_EMAIL__'}); // identify current user for all events
trackPageView() // send pageview event
}, [])
const onClick = (btnName) => {
track('btn_click', {btn: btnName}); // send btn_click event with button name payload on click
}
return (
<button onClick="() => onClick('test_btn')">Test button</button>
)
}
Please note, that useJitsu
uses useEffect()
with related side effects.
To enable automatic pageview tracking, add usePageView()
hook to your _app.js
. This hook will send pageview each time
user loads a new page. This hook relies on NextJS Router
import { createClient, JitsuProvider } from "@jitsu/nextjs";
// initialize Jitsu client
const jitsuClient = createClient({
tracking_host: "__JITSU_HOST__",
key: "__API_KET__",
// See Jitsu SDK parameters section for more options
});
function MyApp({Component, pageProps}) {
usePageView(jitsuClient); // this hook will send pageview track event on router change
// wrap our app with Jitsu provider
return <JitsuProvider client={jitsuClient}>
<Component {...pageProps} />
</JitsuProvider>
}
export default MyApp
If you need to pre-configure jitsu event - for example, identify a user, it's possible to do via before
callback:
usePageView(jitsuClient, {before: (jitsu) => jitsu.id({id: '__USER_ID__', email: '__USER_EMAIL__'})})
Jitsu can track events on server-side:
next export
will not work; fewer data points will be collected - attributes such as screen-size, deviceFor manual tracking you need to initialize Jitsu client
import { createClient } from "@jitsu/nextjs";
// initialize Jitsu client
const jitsuClient = createClient({
tracking_host: "__JITSU_HOST__",
key: "__API_KET__",
// See Jitsu SDK parameters section for more options
});
after that, you will be able to user Jitsu client, for example, in getServerSideProps
export async function getServerSideProps() {
jitsu.track("page_view", {page: req.page})
return { props: {} }
}
Jitsu could track page views automatically via use of _middleware.js
which has been introduced in NextJS 12
export function middleware(req, ev) {
const {page} = req
if ( !page?.name ) {
return;
}
jitsu.track("page_view", {page: req.page})
}
Read about all SDK parameters and methods in our documentation:
createClient()
calluseJitsu()
You can find example app here.
FAQs
Jitsu JavaScript SDK for NextJS (more at http://jitsu.com/docs/js-sdk)
The npm package @jitsu/nextjs receives a total of 119 weekly downloads. As such, @jitsu/nextjs popularity was classified as not popular.
We found that @jitsu/nextjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.