colburncodes / social

Social is a boilerplate that you can use for an unlimited number of projects. Whether you're trying to learn how to structure your own app or want to rapidly spin up a number of features, it sets you up with a powerful set of features.
https://socialio.site
3 stars 1 forks source link

Spike: Evaluating LogSnag for Event Monitoring in Web Applications #73

Open colburncodes opened 5 months ago

colburncodes commented 5 months ago

Log Snag - Realtime monitoring

As a developer, I want to investigate and assess the capabilities of LogSnag for monitoring events in the app. So that I can determine if it meets our requirements for real-time event tracking and is suitable for integration in the development workflow.

Goals of the Spike:

1. Understanding LogSnag's Features:

2. Ease of Integration:

3. Reporting and Documentation

Outcome of the Spike:

Outline the findings and recommendations regarding the adoption of LogSnag for event monitoring, including identified pros and cons, and potential integration strategies.

colburncodes commented 5 months ago

https://docs.logsnag.com/sdks/next

colburncodes commented 3 months ago

Once you set up your account and define the project.

Next, create two tokens SERVER_SIDE_TOKENand CLIENT_SIDE_TOKEN

Pages Directory:

import { LogSnagProvider } from '@logsnag/next';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <LogSnagProvider token='<TOKEN_NAME>' project='<PROJECT_NAME>'>
      {/* Your app content */}
      <Component {...pageProps} />
    </LogSnagProvider>
  );
}

Server-side Usage with Next

import { LogSnag } from '@logsnag/next/server';

// Initialize LogSnagServer
const logsnag = new LogSnag({
  token: '<TOKEN>',
  project: '<PROJECT_NAME>',
});

// Use it in your server-side code
// Track an event
await logsnag.track({
  channel: "payments",
  event: "New Subscription",
  user_id: "user-123",
  icon: "💰",
  notify: true,
  tags: {
    plan: "premium",
    cycle: "monthly",
    trial: false
  }
});

// Identify a user
await logsnag.identify({
  user_id: "user-123",
  properties: {
    name: "John Doe",
    email: "john@doe.com",
    plan: "premium",
  }
});

// Track an insight
await logsnag.insight.track({
  title: "User Count",
  value: "100",
  icon: "👨",
});

// Increment an insight value
await logsnag.insight.increment({
  title: "User Count",
  value: 1,
  icon: "👨",
});