/next-shynet

A library for integrating Shynet (self-hosted privacy-friendly web analytics) into your next.js project.

Primary LanguageTypeScriptMIT LicenseMIT

Next-Shynet

A library for integrating shynet into your next.js project.

It helps to easily use shynet in a single page application. The library also has declarations for typescript.

Usage

Install this library:

npm install next-shynet

App router

Change your app/layout.tsx:

import { ShynetForAppRouter } from "next-shynet"

export default async function RootLayout({children}) {
    return (
        <html>
            <body>
                <ShynetForAppRouter
                    scriptSrc="https://your-shynet-instance/.../index.js"
                    imgSrc="https://your-shynet-instance/.../pixel.gif"
                />
            </body>
        </html>
    )
}

Pages router

Change your _app.js:

import Shynet from "next-shynet"

const YourApp = ({ Component, pageProps }) => (
    <div>
        <Shynet
            scriptSrc="https://your-shynet-instance/.../index.js"
            imgSrc="https://your-shynet-instance/.../pixel.gif" />
        <Component {...pageProps} />
    </div>
)

The link to the tracking pixel is optional.

By default, the script is not loaded during development. To force the script to be included, add the ignoreEnv option:

<Shynet scriptSrc="" ignoreEnv />

How to build

npm install
npm run build

The generated files will be in the /dist directory.

Authors