Skip to content
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

Support for bigint #236

Open
antho1404 opened this issue Jan 15, 2025 · 2 comments
Open

Support for bigint #236

antho1404 opened this issue Jan 15, 2025 · 2 comments

Comments

@antho1404
Copy link

When sending data with mixpanel.track(event, data), if data contains unserializable data such as bigint, the call fails.

It would be great to support bigint in mixpanel and automatically serialize them as string.

The current workaround is to call the following to manually convert these bigint into string so there are no errors in the mixpanel library.

mixpanel.track(event, JSON.parse(
  JSON.stringify(data, (key, value) => {
    if (typeof value === "bigint") return value.toString();
    return value;
  })
))
@hans-lizihan
Copy link
Contributor

you can patch toJSON method on BigInt class if you are sure that you want to send them as string.

BigInt.prototype["toJSON"] = function () {
  return this.toString();
};

@antho1404
Copy link
Author

This is far from ideal as it is changing the default behavior of big int and can have many side effects.
The vest case scenario would be to to the test during the stringify here https://github.com/mixpanel/mixpanel-node/blob/261a98b929e7c2ce6c99d8169335fb06b86ff8d9/lib/mixpanel-node.js#L71C35-L71C49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants