Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analytics Package #38

Open
aklinker1 opened this issue May 27, 2023 · 0 comments
Open

Analytics Package #38

aklinker1 opened this issue May 27, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@aklinker1
Copy link
Owner

Collecting any kind of analytics is hard for web extensions. Google Analytics, the most popular analytics product, doesn't support the chrome extension runtime, neither does Firebase. Other large analytics software (Umami, Amplitude) also don't support chrome extensions, because they all rely on the window object, which doesn't exist in MV3 service workers.

That said, collecting analytics isn't impossible. You just end up writing custom implmentations that interact with the service's API directly, which is kinda a pain.

I'd like to support:

interface ExtensionAnalytics {
  init(context?: string): void;
  trackEvent(action: string, properties: Record<string, any>): void;
  trackPageView(path: string): void;
}

Very basic APIs. As for clients, I'd like to provide GA4 and Umami clients with the package to get started. All will just be HTTP clients.

Initializing analytics should look something like this:

// background.ts
const umamiClient = defineUmamiClient({ ... });
// const googleAnalyticsClient = defineGoogleAnalyticsClient({ ... });
// const allClients = defineMultipleClients(umamiClient, googleAnalyticsClient, ...);
// Or create your own client

const analytics = registerExtensionAnalytics({
  client: umamiClient,
  isEnabled: () => true,
});
analytics.init("background");
// popup.ts
const analytics = getExtensionAnalytics();
analytics.init("popup");
@aklinker1 aklinker1 added the enhancement New feature or request label May 27, 2023
@aklinker1 aklinker1 self-assigned this May 27, 2023
@aklinker1 aklinker1 mentioned this issue May 28, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant