npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mixpanel-figma

v2.0.4

Published

Mixpanel client patched for Figma plugins

Downloads

3,082

Readme

Problem

Original Mixpanel client will NOT work in Figma plugins UI.

Why?
Electron limitation when Iframe content is loaded as Data-URI. Both localStorage and document.cookie are not available (similar problem).

Mixpanel client has configuration option to switch off persistance disable_persistence, but it won't help, as it accesses cookie, which crashes the client 🤷‍♂️.

Fix

Patch the original file to not access document.cookie/localStorage.

Original file - mixpanel/mixpanel-js Patched file – mixpanel-patched.js

Bonus points. Size reduction (~250kb to 130kb).

Mixpanel client is a HUGE file and team is not addressing it.

So I stripped file to make it much smaller. Things removed:

  • mixpanel.group
  • track_links and track_forms
  • notification related things (don't even know what they are)
  • autotrack – some feature Mixpanel discontinued

If size does not bother you or something you need was removed – use npm i [email protected] or raw file (diff)

Usage

Installation

npm i mixpanel-figma
# or using Yarn
yarn add mixpanel-figma

Import package and use client as you usually would.

// main.ts
import * as mixpanel from 'mixpanel-figma'

// disabling via config just in case
mixpanel.init(YOUR_MIXPANEL_KEY, {
  disable_cookie: true,
  disable_persistence: true
})

identify support

Since there is no persistance – every time someone opens your plugin Mixpanel would assume it a unique visitor/user.

To fix that, generate user_id for persistance on main thread side and store it in plugin settings.

CAVEAT Figma plugin settings are tied to Figma instance, so if user uses desktop app on 2 laptops – it will be treated as 2 different users.

// main.ts

const getUserId = async () => {
  let userId = uuid()

  try {
    const id = await figma.clientStorage.getAsync('userId')

    if (typeof id === 'undefined') {
      figma.clientStorage.setAsync('userId', userId)
    } else {
      userId = id
    }
  } catch (e) {
    console.error('userId retrieving error', e)
    figma.clientStorage.setAsync('userId', userId)
  }

  return userId
}
// get or set if not yet set.
const userId = await getUserId()
// send to iframe
figma.ui.sendMessage(userId)


// iframe.ts

// receive userId from main thread and call identify
mixpanel.identify(userId)

License

Apache 2.0