Skip to content

Commit db1d906

Browse files
authored
Add OpenPanel (#33)
* add openpanel * memo * lint * fixing typecheck * adding link/unlink * convert github action to use script * make proper react component * refactor openpanel * we've ported readme to public repo, we can remove this
1 parent 0ef15a8 commit db1d906

File tree

14 files changed

+1578
-1275
lines changed

14 files changed

+1578
-1275
lines changed

.github/workflows/test-cli.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,11 @@ jobs:
223223

224224
- name: Link local packages for testing
225225
run: |
226-
echo "Adding pnpm overrides to use local packages..."
227-
cd test-startup
228-
node -e "
229-
const fs = require('fs');
230-
const workspace = process.env.GITHUB_WORKSPACE;
231-
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
232-
pkg.pnpm = pkg.pnpm || {};
233-
pkg.pnpm.overrides = {
234-
'@startupkit/auth': 'link:' + workspace + '/packages/auth',
235-
'@startupkit/analytics': 'link:' + workspace + '/packages/analytics'
236-
};
237-
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
238-
console.log('Overrides added:', pkg.pnpm.overrides);
239-
"
240-
cat package.json | grep -A 6 '"pnpm"'
241-
working-directory: test-projects
226+
echo "🔗 Linking local @startupkit/* packages..."
227+
node "$GITHUB_WORKSPACE/scripts/link-local.js" link "test-projects/test-startup" "$GITHUB_WORKSPACE/packages"
228+
229+
echo "📄 Verifying changes in packages/analytics/package.json:"
230+
grep -A 2 '@startupkit/analytics' test-projects/test-startup/packages/analytics/package.json || true
242231
243232
- name: Install dependencies in generated project
244233
run: |

apps/home/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"lint:fix": "biome check --write"
1212
},
1313
"dependencies": {
14+
"@openpanel/web": "^1.0.1",
1415
"@radix-ui/react-dialog": "^1.1.1",
1516
"@radix-ui/react-slot": "^1.1.0",
1617
"@radix-ui/react-tooltip": "^1.1.2",
17-
"@startupkit/analytics": "0.2.0",
18+
"@startupkit/analytics": "workspace:*",
1819
"@startupkit/cms": "0.2.0",
1920
"class-variance-authority": "^0.7.0",
2021
"clsx": "^2.1.1",

apps/home/src/components/Features.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ const FEATURES = [
9292
label: "Plausible",
9393
image: require("@/images/integrations/plausible.svg"),
9494
className: "h-6"
95+
},
96+
{
97+
label: "OpenPanel",
98+
image: require("@/images/integrations/openpanel.svg"),
99+
className: "h-6"
95100
}
96101
]
97102
},
Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,69 @@
11
"use client"
22

3+
import { OpenPanel } from "@openpanel/web"
34
import { AnalyticsProvider } from "@startupkit/analytics"
4-
import googleAnalytics from "@startupkit/analytics/ga"
5-
import plausiblePlugin from "@startupkit/analytics/plausible"
6-
import posthogPlugin from "@startupkit/analytics/posthog"
5+
import type { ReactNode } from "react"
6+
import { useEffect, useRef } from "react"
77

8-
const plugins: any[] = [
9-
googleAnalytics({
10-
measurementIds: [process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_ID]
11-
}),
12-
plausiblePlugin({
13-
domain: "startupkit.com",
14-
trackLocalhost: true
15-
}),
16-
posthogPlugin({
17-
token: process.env.NEXT_PUBLIC_POSTHOG_TOKEN || "",
18-
enabled: true,
19-
options: {
20-
persistence: "memory",
21-
disable_cookie: true
22-
}
23-
})
24-
]
8+
const openpanel =
9+
typeof window !== "undefined"
10+
? new OpenPanel({
11+
clientId:
12+
process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID ||
13+
process.env.OPENPANEL_CLIENT_ID ||
14+
"",
15+
trackScreenViews: false,
16+
trackOutgoingLinks: true,
17+
trackAttributes: true
18+
})
19+
: null
2520

2621
export const StartupKitProvider = ({
2722
children
2823
}: Readonly<{
29-
children: React.ReactNode
24+
children: ReactNode
3025
}>) => {
31-
return <AnalyticsProvider plugins={plugins}>{children}</AnalyticsProvider>
26+
const initialized = useRef(false)
27+
28+
useEffect(() => {
29+
if (!initialized.current && openpanel) {
30+
initialized.current = true
31+
}
32+
}, [])
33+
34+
return (
35+
<AnalyticsProvider
36+
flags={{}}
37+
handlers={{
38+
identify: (userId, traits) => {
39+
if (!openpanel) return
40+
if (userId) {
41+
openpanel.identify({
42+
profileId: userId,
43+
...(traits || {})
44+
})
45+
} else {
46+
openpanel.clear()
47+
}
48+
},
49+
track: (event, properties) => {
50+
if (!openpanel) return
51+
openpanel.track(event, properties || {})
52+
},
53+
page: (name, properties) => {
54+
if (!openpanel) return
55+
openpanel.track("$pageview", {
56+
...(properties || {}),
57+
...(name ? { route: name } : {})
58+
})
59+
},
60+
reset: () => {
61+
if (!openpanel) return
62+
openpanel.clear()
63+
}
64+
}}
65+
>
66+
{children}
67+
</AnalyticsProvider>
68+
)
3269
}
Lines changed: 7 additions & 0 deletions
Loading

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"private": true,
78
"scripts": {
89
"clean": "pnpm --stream -r run clean",
@@ -15,7 +16,9 @@
1516
"bump": "./scripts/bump",
1617
"oldrelease": "pnpm --stream --filter \"./packages/**\" exec -- pnpm release --no-git-checks --access public",
1718
"release": "pnpm build && pnpm -r publish --access public --no-git-checks",
18-
"agents.md": "ruler apply"
19+
"agents.md": "ruler apply",
20+
"link:local": "node scripts/link-local.js link",
21+
"unlink:local": "node scripts/link-local.js unlink"
1922
},
2023
"packageManager": "[email protected]",
2124
"author": "Ian Hunter <[email protected]>",
@@ -26,6 +29,7 @@
2629
"@rollup/plugin-commonjs": "^26.0.1",
2730
"@rollup/plugin-swc": "^0.3.1",
2831
"@swc/core": "^1.7.6",
32+
"glob": "^11.0.3",
2933
"rollup": "^4.20.0",
3034
"rollup-plugin-esbuild": "^6.1.1",
3135
"rollup-preserve-directives": "^1.1.1",

0 commit comments

Comments
 (0)