-
Notifications
You must be signed in to change notification settings - Fork 312
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
Fetch adapter #304
Comments
It looks like mixpanel no longer works in service workers for v3 chrome extensions. XHR has been deprecated/removed and fetch is now required. Are there any plan to migrate to fetch, or is there a workaround for service workers? |
Does anyone have an update about this? |
For whoever came here looking for answers, and found none, feel free to use this code. I implemented fetch provisionally, while there's an official answer. |
Thank you @juanfer0002 for adding this! It's funny how the library just silently stops working with manifest v3. @tdumitrescu any idea if/when the PR juanfer created will be reviewed and merged? |
@lukafilipov Since you're using this with the manifest v3, I have to warn you to be extremely careful when reporting to Mixpanel as service workers get shutdown by Chrome every five minutes. This means that if you have identified a user, all events will be associated to them, but after 5m this identification will be lost, making every event not being correctly associated. We had to implement a system to handle this situation, you may end up in a similar one. |
@juanfer0002 Got it, thanks for the heads up! And thanks again for the fix, I've tested it and it just works out of the box. I have referenced your branch directly from package.json like this: |
@juanfer0002 I love you |
Thank you for working on this @juanfer0002. I am wondering if you have encountered these issues (happy to talk privately -what's the best way to do that?):
I get this error right now: "Uncaught TypeError: Cannot set property navigator of # which has only a getter". I can comment out the line, but not sure what that is really doing. Did you consider shifting to the HTTP API? I'm wondering if using mixpanel is worth it. For those working on Chrome extensions.... how are you doing user tracking to learn how they are using product? (I kind of doubt this will get merged into the main - is that right @tdumitrescu or anyone at mixpanel?) |
Take a look at this class @aamirv it helped me a lot, I don't think you have to run it in the background but idk, on plasmo I just made this class and imported it and everything's working so might be running in the background actually. |
@aamirv You can just import files in the background js with normal JS syntax, and then use it as an object. LMK if you need a more precise example, I am responding from my phone. Regarding the other issue, when the SW shuts down, be aware that the callbacks and events are still being fired by Chrome when the port closes, in such a case I Just retry the connection with the service worker. |
so just updating the package.json file will work? No other code change require? |
Is this expected to be added to a mixpanel-js release? |
any updates on this? It's tagged as "enhancement" but it's really a bug that makes mixpanel-browser unusable in chrome extensions |
Seems like real issue right now |
Bump, this is still an issue in V3 |
Very limiting for Web Extension users of Mixpanel. |
I need to use this in a chrome extension and I'm getting an error unless I use juanfer0002:fetch-support-for-mv3-extensions |
Want to use mixpanel for your extension? The easiest way is to write your own code. Reasons
SolutionNote: Doesn't support batch processing! Supports UsageThe typescript code in the GIST returns an object called Hence, all you do is use that object whenever you need. Example // inside an extension service worker
import tracker from "./mixpanel-chrome" // importing from the gist file copy-and-pasted
// initializing mixpanel
tracker.init("<mixpanel-project-id>")
chrome.runtime.onInstalled.addListener((details) => {
// tracking extension install
tracker.track("install", {
extensionVersion: chrome.runtime.getManifest().version
})
})
function signUp(){
const user = getSignUpUser(); // gets signed up user
tracker.identify(user.uid); // mixpanel identify
}
function logout(){
tracker.reset(); // mixpanel user reset on logout
} Visit the Gist |
I disagree if you use a patch like this in pnpm
which adds xhr-shim to mixpanel it works with the most recent versions in chrome-mv3 |
I'm using @doc-han's nice mixpanel client in my extension. I have some mixpanel shared code between the webapp and extension so I instruct webpack to swap out mixpanel-browser for the extension version behind the scenes when building the extension: resolve: {
alias: {
// use chrome extension version of mixpanel client
"mixpanel-browser": resolve(webpackExtSrcDir, "api", "mixpanelExtension.ts"),
},
}, |
Fetch instead of XHR for ServiceWorker compatibility
The text was updated successfully, but these errors were encountered: