{"id":22993636,"url":"https://github.com/okotoki/mixpanel-figma","last_synced_at":"2025-10-09T07:33:34.067Z","repository":{"id":57298642,"uuid":"229844697","full_name":"okotoki/mixpanel-figma","owner":"okotoki","description":"👀Mixpanel-js library patched to be used in Figma plugins.","archived":false,"fork":false,"pushed_at":"2023-09-30T13:17:54.000Z","size":87,"stargazers_count":38,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-26T18:16:43.310Z","etag":null,"topics":["figma","figma-plugins","mixpanel"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/okotoki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-24T00:54:24.000Z","updated_at":"2024-12-08T21:12:39.000Z","dependencies_parsed_at":"2024-06-18T21:22:32.106Z","dependency_job_id":"49f77cf3-ea19-454c-9674-6fef7f90fef8","html_url":"https://github.com/okotoki/mixpanel-figma","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":0.4,"last_synced_commit":"3d42a63548bcf655acea12bd8c994a2196c9da73"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/okotoki/mixpanel-figma","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okotoki%2Fmixpanel-figma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okotoki%2Fmixpanel-figma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okotoki%2Fmixpanel-figma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okotoki%2Fmixpanel-figma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/okotoki","download_url":"https://codeload.github.com/okotoki/mixpanel-figma/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/okotoki%2Fmixpanel-figma/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270328965,"owners_count":24565769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["figma","figma-plugins","mixpanel"],"created_at":"2024-12-15T05:13:47.346Z","updated_at":"2025-10-09T07:33:29.035Z","avatar_url":"https://github.com/okotoki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"media/header.svg\" width=\"800\" alt=\"👀 Mixpanel client patched for Figma plugins\"/\u003e\n\n## Problem\nOriginal Mixpanel client will **NOT** work in Figma plugins UI.\n\n**Why?**  \nElectron limitation when Iframe content is loaded as Data-URI. Both `localStorage` and `document.cookie` are not available ([similar problem](https://stackoverflow.com/questions/44973467/electron-browserwindow-facebook-login-failed-to-set-cookies)).\n\nMixpanel client has configuration option to switch off persistance `disable_persistence`, but it won't help, as it accesses `cookie`, which  crashes the client 🤷‍♂️.\n\n## Fix\nPatch the original file to not access `document.cookie`/`localStorage`.\n\nOriginal file - [mixpanel/mixpanel-js](https://github.com/mixpanel/mixpanel-js/blob/1c4d98b4a485fbf4dc4421f00c33f3b19530b307/dist/mixpanel.cjs.js)\nPatched file – [mixpanel-patched.js](mixpanel-patched.js)\n\n## Bonus points. Size reduction (~250kb to 130kb).\nMixpanel client is a HUGE file and team is [not addressing it](https://github.com/mixpanel/mixpanel-js/issues/128).\n\nSo I stripped file to make it much smaller. Things removed:  \n- [mixpanel.group](https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-group)\n- [track_links](https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-track-links) and track_forms\n- notification related things (don't even know what they are)\n- autotrack – some feature Mixpanel discontinued\n\nIf size does not bother you or something you need was removed – use `npm i mixpanel-figma@1.0.0` or [raw file](https://github.com/okotoki/mixpanel-figma/blob/master/mixpanel-patched.js) ([diff](https://github.com/okotoki/mixpanel-figma/commit/3c161fb714fd6bab1c21b9f3aea48c5f2e0a0f43))\n\n## Usage\n\nInstallation\n```sh\nnpm i mixpanel-figma\n# or using Yarn\nyarn add mixpanel-figma\n```\n\nImport package and use client as you usually would.\n```typescript\n// main.ts\nimport * as mixpanel from 'mixpanel-figma'\n\n// disabling via config just in case\nmixpanel.init(YOUR_MIXPANEL_KEY, {\n  disable_cookie: true,\n  disable_persistence: true\n})\n\n```\n\n## `identify` support\n\nSince there is no persistance – every time someone opens your plugin Mixpanel would assume it a unique visitor/user.\n\nTo fix that, generate user_id for persistance on main thread side and store it in plugin settings.\n\n**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.\n\n```typescript \n// main.ts\n\nconst getUserId = async () =\u003e {\n  let userId = uuid()\n\n  try {\n    const id = await figma.clientStorage.getAsync('userId')\n\n    if (typeof id === 'undefined') {\n      figma.clientStorage.setAsync('userId', userId)\n    } else {\n      userId = id\n    }\n  } catch (e) {\n    console.error('userId retrieving error', e)\n    figma.clientStorage.setAsync('userId', userId)\n  }\n\n  return userId\n}\n// get or set if not yet set.\nconst userId = await getUserId()\n// send to iframe\nfigma.ui.sendMessage(userId)\n\n\n// iframe.ts\n\n// receive userId from main thread and call identify\nmixpanel.identify(userId)\n```\n\n## License\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokotoki%2Fmixpanel-figma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fokotoki%2Fmixpanel-figma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fokotoki%2Fmixpanel-figma/lists"}