Skip to content

Commit

Permalink
Add Analytics class scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jan 28, 2025
1 parent 7052152 commit 581974a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/analytics-nextjs/src/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { AnalyticsBrowser } from '@segment/analytics-next';
import type Plausible from 'plausible-tracker';
import type { PlausibleOptions } from 'plausible-tracker';

interface Config {
isEnabled: boolean;
plausibleOptions?: PlausibleOptions;
}

export class Analytics {
public segment: AnalyticsBrowser | undefined = undefined;

public plausible: ReturnType<typeof Plausible> | undefined = undefined;

private config: Config;

constructor(config: Config) {
this.config = config;
this.init();
}

async init() {
const [{ AnalyticsBrowser }, { default: Plausible }] = await Promise.all([
import('@segment/analytics-next'),
import('plausible-tracker'),
]);

this.segment = new AnalyticsBrowser();
this.plausible = Plausible(this.config.plausibleOptions);
}
}

0 comments on commit 581974a

Please sign in to comment.