Product analytics for browser extensions

Last updated:

Do you have a Firefox or Chrome browser plugin with a user interface and want to understand how it's being used? PostHog is the perfect way to do just that.

Setup for Firefox & Chrome plugins

Installing PostHog inside your plugin

Open the HTML file used in your default_popup and add the PostHog array.js script. To do this you'll need to either:

  1. Copy the latest version of array.js from: https://app.posthog.com/static/array.js and import it locally using <script src="array.js" /> before the </head> tag
  2. If you're packaging your plugin automatically use the npm module for posthog.js

All you need to do now is initialize PostHog, add the following code to a new js file and import it into your default_popup html file to initiate PostHog.

JavaScript
posthog.init('your_project_token',{api_host:'https://app.posthog.com',persistence:'localStorage'})
  • your_project_token - This is the Project API key which can be found on PostHog under Project Settings
  • api_host - This is the URL to your PostHog instance (if you're not using PostHog Cloud)
  • persistence - This indicates we should store user data in localStorage rather than cookies - there are issues with cookie persistence on Firefox plugins

Tracking events

One of the best things about using PostHog is, all the interactions like clicks will automatically generate events in PostHog, so you don't need to do anything else to start analyzing.

If you'd like to instrument your own custom events, all you need to do is:

JavaScript
posthog.capture('custom_event_name', {})

See our JS library guide for more details

Questions?

Was this page useful?

Next article

Self-host PostHog

The fastest and most reliable way to get started with PostHog is to use PostHog Cloud . However, if you're a large company with the need to self-host or an engineer looking to use the open-source version in a funky non-production way then you're in the right place! PostHog Open-Source The core of PostHog is open-source and always will be. For more information on deployment go to open-source deployment .

Read next article