@nexly/next 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nexly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @nexly/next
2
+
3
+ Next.js App Router helpers for **[@nexly/react-web](https://www.npmjs.com/package/@nexly/react-web)**.
4
+
5
+ The base `@nexly/react-web` provider fires a pageview once on mount. In Next.js App Router, client navigations do not remount the root layout, so subsequent route changes are missed. `@nexly/next` adds a thin wrapper that listens to `usePathname()` and sends a pageview on every route change.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @nexly/next
11
+ ```
12
+
13
+ `@nexly/react-web` and `@nexly/core` are installed automatically as transitive dependencies.
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ // app/providers.tsx
19
+ 'use client'
20
+
21
+ import { NexlyNextProvider } from '@nexly/next'
22
+
23
+ export function Providers({ children }: { children: React.ReactNode }) {
24
+ return (
25
+ <NexlyNextProvider
26
+ appId={process.env.NEXT_PUBLIC_NEXLY_APP_ID!}
27
+ ingestKey={process.env.NEXT_PUBLIC_NEXLY_INGEST_KEY!}
28
+ autoPageView
29
+ autoEngagement
30
+ >
31
+ {children}
32
+ </NexlyNextProvider>
33
+ )
34
+ }
35
+ ```
36
+
37
+ ```tsx
38
+ // app/layout.tsx
39
+ import { Providers } from './providers'
40
+
41
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
42
+ return (
43
+ <html lang="en">
44
+ <body>
45
+ <Providers>{children}</Providers>
46
+ </body>
47
+ </html>
48
+ )
49
+ }
50
+ ```
51
+
52
+ ### Custom events
53
+
54
+ ```tsx
55
+ 'use client'
56
+
57
+ import { useNexlyClient } from '@nexly/next'
58
+
59
+ export function SignUpButton() {
60
+ const client = useNexlyClient()
61
+ return (
62
+ <button onClick={() => client?.event({ name: 'sign_up', type: 'conversion' })}>
63
+ Sign up
64
+ </button>
65
+ )
66
+ }
67
+ ```
68
+
69
+ ### Props
70
+
71
+ `NexlyNextProvider` accepts the same props as `NexlyProvider` from `@nexly/react-web`:
72
+
73
+ - **`appId`**, **`ingestKey`** — required credentials.
74
+ - **`autoPageView`** (default `false`) — send a pageview on mount and on every client-side route change.
75
+ - **`autoEngagement`** (default `false`) — attach scroll, click, visibility, and heartbeat listeners.
76
+
77
+ ### Re-exports
78
+
79
+ `useNexlyClient` is re-exported from `@nexly/react-web` for convenience — no need to install the base package separately.
80
+
81
+ ## License
82
+
83
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,3 @@
1
+ export { NexlyNextProvider, type NexlyNextProviderProps } from './nexly-next-provider.js';
2
+ export { useNexlyClient } from '@nexly/react-web';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { NexlyNextProvider } from './nexly-next-provider.js';
2
+ export { useNexlyClient } from '@nexly/react-web';
@@ -0,0 +1,18 @@
1
+ import { type NexlyProviderProps } from '@nexly/react-web';
2
+ export type NexlyNextProviderProps = Omit<NexlyProviderProps, 'autoPageView'> & {
3
+ /**
4
+ * Track pageviews automatically on every client-side route change (via `usePathname`).
5
+ * Unlike the base `autoPageView` in `@nexly/react-web` (fires once on mount),
6
+ * this fires on **every** App Router navigation.
7
+ * @default false
8
+ */
9
+ autoPageView?: boolean;
10
+ };
11
+ /**
12
+ * Drop-in replacement for `NexlyProvider` in Next.js App Router apps.
13
+ *
14
+ * When `autoPageView` is `true`, a pageview is sent on mount **and** on every
15
+ * subsequent client-side navigation (pathname change).
16
+ */
17
+ export declare function NexlyNextProvider({ autoPageView, children, ...rest }: NexlyNextProviderProps): import("react/jsx-runtime").JSX.Element;
18
+ //# sourceMappingURL=nexly-next-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexly-next-provider.d.ts","sourceRoot":"","sources":["../src/nexly-next-provider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiC,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAuBzF,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,GAAG;IAC9E;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,YAAoB,EACpB,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,sBAAsB,2CAOxB"}
@@ -0,0 +1,32 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { NexlyProvider, useNexlyClient } from '@nexly/react-web';
4
+ import { usePathname } from 'next/navigation';
5
+ import { useEffect, useRef } from 'react';
6
+ /**
7
+ * Invisible component that sends a pageview whenever the App Router pathname changes.
8
+ * Lives inside `NexlyProvider` so it can read the client from context.
9
+ */
10
+ function RoutePageviews() {
11
+ const pathname = usePathname();
12
+ const client = useNexlyClient();
13
+ const prevRef = useRef('');
14
+ useEffect(() => {
15
+ if (!client || !pathname)
16
+ return;
17
+ if (prevRef.current === pathname)
18
+ return;
19
+ prevRef.current = pathname;
20
+ client.pageview(pathname);
21
+ }, [client, pathname]);
22
+ return null;
23
+ }
24
+ /**
25
+ * Drop-in replacement for `NexlyProvider` in Next.js App Router apps.
26
+ *
27
+ * When `autoPageView` is `true`, a pageview is sent on mount **and** on every
28
+ * subsequent client-side navigation (pathname change).
29
+ */
30
+ export function NexlyNextProvider({ autoPageView = false, children, ...rest }) {
31
+ return (_jsxs(NexlyProvider, { ...rest, autoPageView: false, children: [autoPageView && _jsx(RoutePageviews, {}), children] }));
32
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@nexly/next",
3
+ "version": "0.3.0",
4
+ "description": "Next.js App Router helpers for Nexly: route-aware auto pageview on top of @nexly/react-web",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "nexly",
8
+ "next",
9
+ "nextjs",
10
+ "analytics",
11
+ "tracking"
12
+ ],
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
+ }
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.build.json",
34
+ "clean": "rm -rf dist"
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "peerDependencies": {
40
+ "next": ">=14.0.0",
41
+ "react": "^18.0.0 || ^19.0.0"
42
+ },
43
+ "dependencies": {
44
+ "@nexly/react-web": "0.3.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "^19.2.14",
48
+ "next": "^15.3.1",
49
+ "react": "^19.1.0",
50
+ "typescript": "~6.0.2"
51
+ }
52
+ }