MCPcopy Create free account
hub / github.com/Xtremilicious/projectlearn-project-based-learning / handler

Function handler

pages/api/init-analytics.ts:4–28  ·  view source on GitHub ↗
(req: NextApiRequest, res: NextApiResponse)

Source from the content-addressed store, hash-verified

2import { init } from '@amplitude/analytics-browser';
3
4export default function handler(req: NextApiRequest, res: NextApiResponse) {
5 if (req.method === 'POST') {
6 try {
7 const apiKey = process.env.AMPLITUDE_API_KEY;
8 if (!apiKey) {
9 return res.status(500).json({ error: 'Amplitude API key not defined' });
10 }
11
12 //init(apiKey); // Initialize Amplitude
13 res.status(200).json({ message: 'Amplitude initialized successfully' });
14
15 // Log initialization in development mode
16 if (process.env.NODE_ENV === 'development') {
17 console.log('Amplitude initialized');
18 }
19 } catch (error) {
20 console.error('Error initializing Amplitude:', error);
21 res.status(500).json({ error: 'Failed to initialize Amplitude' });
22 }
23 } else {
24 // Handle any other HTTP method
25 res.setHeader('Allow', ['POST']);
26 res.status(405).end(`Method ${req.method} Not Allowed`);
27 }
28}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected