-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ added openpanel analytics along with ga (#81)
* feat: ✨ added openpanel analytics along with ga * fix: 🐛 fixed them provider issue * fix: 🐛 fixed lint issue
- Loading branch information
Showing
17 changed files
with
675 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
*.md | ||
pnpm-lock.yaml | ||
*-lock.yaml | ||
node_modules | ||
.next | ||
.turbo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@ultra-reporter/analytics", | ||
"description": "Ultra Reporter Analytics", | ||
"version": "0.4.0", | ||
"private": true, | ||
"scripts": { | ||
"lint": "eslint . --max-warnings 0" | ||
}, | ||
"exports": { | ||
"./server": "./src/server.ts", | ||
"./client": "./src/client.tsx" | ||
}, | ||
"dependencies": { | ||
"@openpanel/nextjs": "^1.0.5", | ||
"@vercel/functions": "^1.5.0", | ||
"@ultra-reporter/utils": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.3.12", | ||
"@ultra-reporter/logger": "workspace:*", | ||
"@ultra-reporter/typescript-config": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable react/react-in-jsx-scope */ | ||
import { | ||
OpenPanelComponent, | ||
type PostEventPayload, | ||
useOpenPanel, | ||
} from '@openpanel/nextjs'; | ||
import { logger } from '@ultra-reporter/logger'; | ||
import { isProd } from '@ultra-reporter/utils/constants'; | ||
|
||
const Provider = () => ( | ||
<OpenPanelComponent | ||
clientId={process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID!} | ||
trackAttributes={true} | ||
trackScreenViews={isProd} | ||
trackOutgoingLinks={isProd} | ||
/> | ||
); | ||
|
||
const track = (options: { event: string } & PostEventPayload['properties']) => { | ||
const { track: openTrack } = useOpenPanel(); | ||
|
||
if (!isProd) { | ||
logger.info('Track', options); | ||
return; | ||
} | ||
|
||
const { event, ...rest } = options; | ||
openTrack(event, rest); | ||
}; | ||
|
||
export { Provider, track }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { OpenPanel, type PostEventPayload } from '@openpanel/nextjs'; | ||
import { logger } from '@ultra-reporter/logger'; | ||
import { waitUntil } from '@vercel/functions'; | ||
|
||
type Props = { | ||
userId?: string; | ||
fullName?: string | null; | ||
}; | ||
|
||
export const setupAnalytics = async (options?: Props) => { | ||
const { userId, fullName } = options ?? {}; | ||
|
||
const client = new OpenPanel({ | ||
clientId: process.env.NEXT_PUBLIC_OPENPANEL_CLIENT_ID!, | ||
clientSecret: process.env.OPENPANEL_SECRET_KEY!, | ||
}); | ||
|
||
if (userId && fullName) { | ||
const [firstName, lastName] = fullName.split(' '); | ||
|
||
waitUntil( | ||
client.identify({ | ||
profileId: userId, | ||
firstName, | ||
lastName, | ||
}) | ||
); | ||
} | ||
|
||
return { | ||
track: (options: { event: string } & PostEventPayload['properties']) => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.info('Track', options); | ||
return; | ||
} | ||
|
||
const { event, ...rest } = options; | ||
waitUntil(client.track(event, rest)); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@ultra-reporter/typescript-config/react-library.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["dist", "build", "node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@ultra-reporter/logger", | ||
"description": "Ultra Reporter Analytics", | ||
"version": "0.4.0", | ||
"private": true, | ||
"main": "./src/index.ts", | ||
"scripts": { | ||
"lint": "eslint . --max-warnings 0" | ||
}, | ||
"dependencies": { | ||
"pino": "^9.5.0" | ||
}, | ||
"devDependencies": { | ||
"@ultra-reporter/typescript-config": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import pino from 'pino'; | ||
|
||
export const logger = pino(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@ultra-reporter/typescript-config/react-library.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src"], | ||
"exclude": ["dist", "build", "node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const isProd = process.env.NODE_ENV === 'production'; | ||
|
||
export { isProd }; |
Oops, something went wrong.