Code Monkey home page Code Monkey logo

storybook-addon-amplitude's Introduction

storybook-addon-amplitude

A storybook addon to capture events in Amplitude.

Read the blog post here.

What does it do?

The Amplitude Storybook add-on emits events to Amplitude on two different occasions: when a user navigates to a new page and when a user changes a story's args.

Getting Started

The first thing you’ll need to do is sign up for Amplitude. If you already have an account, great! If you don’t, you can sign up here for free.

Once you have an account, you can create a new project which will have an associated API key.

To do this, navigate to the Settings page.

Screen Shot 2022-06-15 at 4 12 52 PM

Then, select Projects in the sidebar.

Screen Shot 2022-06-15 at 4 15 33 PM

In the top right hand corner, click the Create Project button and follow the instructions.

Screen Shot 2022-06-15 at 4 17 13 PM

Next, install the package as a devDependency in your project:

yarn add @amplitude/storybook-addon-amplitude --dev

in storybook/main.js

module.exports: {
  addons: [
+   '@amplitude/storybook-addon-amplitude/preset',
  ]
}

Then, set your Amplitude API keys in ./storybook/manager.js

window.AMPLITUDE_DEV_API_KEY = '<amplitude-dev-api-key>';
window.AMPLITUDE_PROD_API_KEY = '<amplitude-prod-api-key>';

If you want to post to the EU endpoint make sure to set the serverUrl option:

window.AMPLITUDE_OPTIONS = {
  serverUrl: 'https://api.eu.amplitude.com/2/httpapi',
};

Read more: Configurations, Endpoints

If you are in a typescript project you might want to add the following declarations:

declare global {
  interface Window {
    AMPLITUDE_DEV_API_KEY: string;
    AMPLITUDE_PROD_API_KEY: string;
    AMPLITUDE_OPTIONS: {
      serverUrl?: string;
    };
  }
}

Now your storybook will begin emitting events to your project in Amplitude. You’re ready to start creating charts in Amplitude!

Example Charts

Weekly unique users viewing Storybook documentation

Screen Shot 2022-05-24 at 1 04 57 PM

Most commonly referenced Storybook categories

Screen Shot 2022-05-31 at 1 54 41 PM

Event Taxonomy

User navigates to a new page

When a user switches to a new page, this add-on emits an event to Amplitude that looks like this:

{
  event_type: "viewed documentation", 
  event_properties: {
    category: 'variants', 
    page: "secondarybuttongroup"
  }
}

Tracking the event in this way allows you to build charts in Amplitude to show:

  1. How many people have viewed your Storybook over time
  2. What categories people are viewing most frequently
  3. What pages people are viewing most frequently

User changes a story’s args

When a user changes a story's args, this add-on emits an event that looks like this:

{
  event_type: "updated story args", 
  event_properties: {
    category: 'variants', 
    page: "secondarybuttongroup"
  }
}

Tracking the event in this way allows you to build charts in Amplitude to answer:

  1. How often do people use the story args functionality?
  2. In which category of pages people update the story args most frequently?
  3. On which pages people update the story args most frequently?

Credits

Created by: Mae Capozzi

Maintained by: Mae Capozzi, Jack McCloy, and Jimmy Wilson

storybook-addon-amplitude's People

Contributors

maecapozzi avatar dependabot[bot] avatar jimmynotjim avatar tijmenvangurp avatar kaelig avatar

Stargazers

Şahin Arslan avatar  avatar Shawn McKay avatar Roewyn Umayam avatar Kelly Harrop avatar Leonardo Oliva Kraciunas avatar  avatar  avatar

Watchers

James Cloos avatar Jeffrey Wang avatar Nirmal Utwani avatar Julien Dubeau avatar Curtis Liu avatar Jack McCloy avatar  avatar Rupa Parameswaran avatar

storybook-addon-amplitude's Issues

Tracking addon panel usage

First of all, thank you so much for making this addon!

Our team was wondering if it was possible to track when users navigate through the tabs in the addon panel.

Support for nested stories/ folders

I'm just playing around with this for the first time and followed the guide for setting up reports/charts. I'm getting data into my Amplitude dashboard, but all of my nested stories (that is all of my stories because they are all organized in folders) report the page as 'dropdown', so the data is not very useful.

Is there a way to configure the plugin to work with stories/pages that are grouped into folders?

This is roughly how my stories are organized:
image

Track the number of times the code is copied

This is what our team would like to request. Thank you!

User story: As a product manager, I would like to be able to track the usage of the Copy Code button in Storybook or the number of times that the code has been copied and for which variant, so that I can determine which variants are the most popularly used in our design system.

Also, thank you for all the work on the add-on! This is great!

Storybook 8 compatibility

Hey @maecapozzi! I’m reaching out from the core SB team :)

Storybook 8 (our next major release) is coming soon, and it introduces some breaking changes that your addon might need to account for.

We’ve listed all the key changes in a new Storybook 8 migration guide, and we’d encourage you to check it out and see if your addon is impacted.

We also have an addons channel in our Discord community, which we’d like to use to better communicate with addon authors in the future. If you’re not part of the server, consider joining here and message me (@joevaugh4n) so that I can give you the addon creator role! If you’re already in the server, please just ping me and I’ll respond to you there.

Thanks for being a part of our addon community!

Joe

Use the new Framework API?

Hey @maecapozzi!
I'm one of the Storybook maintainers. I focus primarily on documentation and community outreach. I'm opening up this issue and letting you know that the Storybook API for building addons is currently being updated to factor in the changes introduced by the upcoming 7.0 release. If you're interested in making the required changes to help the community from benefiting from using your addon, we've prepared an abridged guide for the required changes here, and if you have any questions or issues, please reach out to us in the #prerelease channel in our Discord Server.

Hope you have a great day!

Stay safe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.