add nextjs with approuter example

This commit is contained in:
goenning 2023-08-31 16:16:38 +01:00
parent 7c9dc72df1
commit 90317d71d3
18 changed files with 623 additions and 2040 deletions

7
.gitignore vendored
View file

@ -14,9 +14,6 @@ coverage
# debug # debug
npm-debug.log* npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# local env files # local env files
.env.local .env.local
@ -27,4 +24,6 @@ yarn-error.log*
# turbo # turbo
.turbo .turbo
dist # bundler output
dist
.next

View file

@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View file

@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
module.exports = nextConfig

View file

@ -0,0 +1,21 @@
{
"name": "next-with-approuter",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@types/node": "20.5.7",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"next": "13.4.19",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2",
"@aptabase/next": "*"
}
}

View file

@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}

View file

@ -0,0 +1,9 @@
import { getName } from '@aptabase/next'
export default function Home() {
return (
<main>
Hello from Next.js App Router: {getName()}
</main>
)
}

View file

@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

2435
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"workspaces": [ "workspaces": [
"examples/*",
"packages/*" "packages/*"
], ],
"scripts": { "scripts": {
@ -11,9 +12,8 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"" "format": "prettier --write \"**/*.{ts,tsx,md}\""
}, },
"devDependencies": { "devDependencies": {
"prettier": "latest", "prettier": "3.0.3",
"turbo": "latest", "turbo": "1.10.13"
"turboversion": "^0.1.0"
}, },
"engines": { "engines": {
"npm": ">=7.0.0", "npm": ">=7.0.0",
@ -23,6 +23,5 @@
"singleQuote": true, "singleQuote": true,
"tabWidth": 2, "tabWidth": 2,
"printWidth": 120 "printWidth": 120
}, }
"packageManager": "yarn@1.22.5"
} }

View file

View file

@ -0,0 +1,47 @@
{
"name": "@aptabase/next",
"version": "0.0.1",
"private": false,
"type": "module",
"description": "Next.js SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/aptabase/aptabase-js.git",
"directory": "packages/js"
},
"bugs": {
"url": "https://github.com/aptabase/aptabase-js/issues"
},
"homepage": "https://github.com/aptabase/aptabase-js",
"license": "MIT",
"scripts": {
"build": "rollup -c ./rollup.config.mjs",
"watch": "rollup -c ./rollup.config.mjs -w",
"prepublishOnly": "npm run build",
"pretest": "npm run build"
},
"files": [
"README.md",
"LICENSE",
"dist",
"package.json"
],
"devDependencies": {
"@rollup/plugin-replace": "5.0.2",
"@rollup/plugin-typescript": "11.1.3",
"rollup": "3.28.1",
"@rollup/plugin-terser": "0.4.3",
"tslib": "2.6.2",
"typescript": "5.2.2"
}
}

View file

@ -0,0 +1,38 @@
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json' assert { type: 'json' };
const plugins = [
terser(),
replace({
'env.PKG_VERSION': pkg.version,
preventAssignment: true,
}),
typescript({
tsconfig: './tsconfig.json',
moduleResolution: 'node',
}),
];
const cjs = {
input: './src/index.ts',
output: {
dir: './dist',
entryFileNames: '[name].js',
format: 'cjs',
},
plugins,
};
const es = {
input: './src/index.ts',
output: {
dir: './dist',
entryFileNames: '[name].mjs',
format: 'es',
},
plugins,
};
export default [cjs, es];

View file

@ -0,0 +1,3 @@
export function getName() {
return "next"
}

View file

@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES5",
"strict": true,
"allowJs": true,
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"types": ["@types"]
},
"declaration": true,
"declarationDir": "./dist",
"rootDir": "./src"
},
"include": ["./"]
}

View file

@ -1,3 +0,0 @@
node_modules
dist
.DS_Store

View file

@ -13,11 +13,7 @@ A tiny SDK (1 kB) to instrument your web app with Aptabase, an Open Source, Priv
Install the SDK using your preferred JavaScript package manager Install the SDK using your preferred JavaScript package manager
```bash ```bash
pnpm add @aptabase/web
# or
npm add @aptabase/web npm add @aptabase/web
# or
yarn add @aptabase/web
``` ```
## Usage ## Usage
@ -27,9 +23,9 @@ First you need to get your `App Key` from Aptabase, you can find it in the `Inst
Initialized the SDK using your `App Key`: Initialized the SDK using your `App Key`:
```js ```js
import { init } from "@aptabase/web"; import { init } from '@aptabase/web';
init("<YOUR_APP_KEY>"); // 👈 this is where you enter your App Key init('<YOUR_APP_KEY>'); // 👈 this is where you enter your App Key
``` ```
The init function also supports an optional second parameter, which is an object with the `appVersion` property. The init function also supports an optional second parameter, which is an object with the `appVersion` property.
@ -39,10 +35,10 @@ It's up to you to decide what to get the version of your app, but it's generally
Afterwards you can start tracking events with `trackEvent`: Afterwards you can start tracking events with `trackEvent`:
```js ```js
import { trackEvent } from "@aptabase/web"; import { trackEvent } from '@aptabase/web';
trackEvent("connect_click"); // An event with no properties trackEvent('connect_click'); // An event with no properties
trackEvent("play_music", { name: "Here comes the sun" }); // An event with a custom property trackEvent('play_music', { name: 'Here comes the sun' }); // An event with a custom property
``` ```
A few important notes: A few important notes:

View file

@ -27,8 +27,8 @@
"scripts": { "scripts": {
"build": "rollup -c ./rollup.config.mjs", "build": "rollup -c ./rollup.config.mjs",
"watch": "rollup -c ./rollup.config.mjs -w", "watch": "rollup -c ./rollup.config.mjs -w",
"prepublishOnly": "yarn build", "prepublishOnly": "npm run build",
"pretest": "yarn build" "pretest": "npm run build"
}, },
"files": [ "files": [
"README.md", "README.md",
@ -38,10 +38,10 @@
], ],
"devDependencies": { "devDependencies": {
"@rollup/plugin-replace": "5.0.2", "@rollup/plugin-replace": "5.0.2",
"@rollup/plugin-typescript": "11.1.0", "@rollup/plugin-typescript": "11.1.3",
"rollup": "3.21.6", "rollup": "3.28.1",
"@rollup/plugin-terser": "0.4.1", "@rollup/plugin-terser": "0.4.3",
"tslib": "2.5.0", "tslib": "2.6.2",
"typescript": "5.0.4" "typescript": "5.2.2"
} }
} }