Skip to content

Conversation

@santigracia
Copy link
Contributor

@santigracia santigracia commented Nov 13, 2025

  • Adding configurable import batch size (1-2000)

  • Adding customizable connection and read timeouts

  • Adding retries with payload chunking for 413 errors in import (payload too large/10MB limit)

  • Adding option to disable strict import validation (optional strict=0)

  • Adding HTTP response logging for import endpoint errors

  • Deprecating trackCharge() method - now logs error instead of tracking revenue

  • Support decimal increments in increment() method

  • Enforcing non-empty token for MessageBuilder and import

  • Bumping org.json dependency version

More details in each commit notes

GitHub Copilot Summary

This pull request introduces several improvements and updates to the Mixpanel Java SDK, focusing on enhanced import functionality, deprecation handling, and improved documentation. The most important changes include support for custom import batch sizes, explicit deprecation of the trackCharge method, and updates to the demo and documentation to reflect these changes.

Import Functionality Improvements

  • Added support for configuring a custom batch size (between 1 and 2000) for the /import endpoint via new constructors in MixpanelAPI, helping to avoid exceeding the 10MB payload limit. This is demonstrated in both the demo code and documentation. [1] [2] [3] [4] [5] [6]
  • Introduced the ability to disable strict validation mode for imports using disableStrictImport(), as documented in the updated README.md. [1] [2]

Deprecated Revenue Tracking

  • Explicitly deprecated the trackCharge method in MessageBuilder, which now logs an error and returns null instead of tracking revenue, with clear messaging and documentation updates. [1] [2] [3]

Demo and Documentation Updates

  • Updated MixpanelAPIDemo.java to demonstrate new features: custom import batch size, handling of deprecated trackCharge, and improved thread management for different delivery scenarios. [1] [2] [3] [4] [5] [6]
  • Enhanced the README.md with sections on custom import batch size and strict import validation, including usage examples.

API Consistency and Type Safety

  • Updated the increment method in MessageBuilder to accept a Map<String, Number> instead of Map<String, Long>, allowing both integer and decimal increments for profile properties.

Dependency Update

  • Upgraded the org.json library dependency to version 20250517 in pom.xml for improved compatibility and security.

Support custom batch sizes for /import endpoint to prevent 413 errors when events exceed server's 1MB payload limit.

- Two new constructors: MixpanelAPI(int batchSize) and MixpanelAPI(boolean gzip, int batchSize)
- Batch size clamped to [1, 2000] range (default: 2000)
- Only affects /import endpoint; other endpoints unaffected
- Fully backward compatible
- Includes tests and updated demo and README
Capture and include HTTP status code and response body in import endpoint exceptions for better error diagnostics.
…evenue

Deprecate the trackCharge() method following the same pattern as the JavaScript SDK. The method now only logs an error to stderr and returns null instead of creating profile properties.

The old version of Mixpanel's Revenue analysis UI has been replaced by a newer suite of analysis tools which don't depend on profile properties. See https://docs.mixpanel.com/docs/features/revenue_analytics for more information.

BREAKING CHANGE: Existing code calling trackCharge() will still compile and run, but the method will no longer have any effect and will log an error message. Customers using the old Revenue Report should migrate to alternative revenue tracking approaches. Reach out to [email protected] for help.

- Mark trackCharge(String, double, JSONObject) as @deprecated
- Mark trackCharge(String, double, JSONObject, JSONObject) as @deprecated
- Both methods now log deprecation error to System.err
- Both methods return null instead of creating profile updates
- Update tests to verify null return value
- Update demo to show deprecated behavior
Update increment() method to accept Map<String, Number> instead of Map<String, Long> enabling decimal and mixed numeric increments.

Changes:
- Replace Map<String, Long> with Map<String, Number> in both increment() overloads
- Enables decimal increments like 4.5, 2.7, 10.50
- Maintains backward compatibility - existing code continues to work
- Add testIncrementWithDecimals() test verifying decimal support
- Update all existing test calls to use Map<String, Number>
Allow per-instance customization of connection and read timeouts for HTTP requests, enabling better support for high-latency regions and slow networks.
Introduces PayloadChunker to split large JSON payloads when a 413 Payload Too Large error is received from the server. Updates MixpanelAPI to retry sending chunked payloads for both /track and /import endpoints, with configurable size limits. Refactors sendData to return HTTP status codes, and enhances test coverage for chunking logic and 413 error handling.
Introduces the disableStrictImport() method to MixpanelAPI, allowing users to set strict=0 for import operations and bypass event validation. Updates documentation and adds tests to verify the new behavior and ensure strict mode is instance-specific.
…andle 400 'request body too large' with chunked retry

Extend import endpoint error handling to retry with chunked payloads when a 400 Bad Request is received with a 'request body too large' message, in addition to 413 errors. Improve PayloadChunker performance by tracking cumulative size, and add tests to verify correct chunking and error handling for 400 responses.
Updated Javadoc and in-code comments to clarify the behavior of the /import endpoint with strict=1 and strict=0 parameters. Enhanced sendImportData to explicitly handle plain text responses for strict=0 mode, returning appropriate results and status codes based on the response format.
Added validation to ensure the Mixpanel project token is not null or empty in MessageBuilder and when sending import messages in MixpanelAPI. This prevents accidental usage with invalid tokens and ensures proper authentication for the /import endpoint
Bump org.json library from version 20231013 to 20250517 to use the latest features and bug fixes.
@santigracia santigracia marked this pull request as draft November 13, 2025 22:55
Enhanced JavaDoc comments across core classes to clarify constructor parameters, method behaviors, and field purposes.
@santigracia santigracia marked this pull request as ready for review November 16, 2025 19:23
Copilot finished reviewing on behalf of jaredmixpanel November 17, 2025 17:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds multiple improvements to the Mixpanel Java SDK focused on better control over import operations, error handling, and API flexibility. The changes include configurable import batch sizes (1-2000), customizable HTTP timeouts, automatic retry with payload chunking for 413 errors, optional strict import validation mode, and support for decimal increments. The deprecated trackCharge() method now returns null and logs an error message.

Key changes:

  • Configurable import batch size and HTTP timeouts for better performance tuning
  • Automatic payload chunking and retry logic for 413 "Payload Too Large" errors
  • Token validation enforcement for MessageBuilder and import operations

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/java/com/mixpanel/mixpanelapi/PayloadChunker.java New utility class for splitting large JSON payloads into smaller chunks when 413 errors occur
src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java Added configurable batch sizes, HTTP timeouts, strict mode toggle, 413 error handling with automatic chunking, and token validation
src/main/java/com/mixpanel/mixpanelapi/MessageBuilder.java Deprecated trackCharge() method, changed increment() to accept Map<String, Number> for decimal support, added token validation
src/main/java/com/mixpanel/mixpanelapi/Config.java Added HTTP status code constants and payload size limits for track (1MB) and import (10MB) endpoints
src/test/java/com/mixpanel/mixpanelapi/MixpanelAPITest.java Comprehensive test coverage for new features including chunking, custom batch sizes, 413 handling, strict mode, and deprecated methods
src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java Updated demo to showcase custom batch size and properly handle deprecated trackCharge() method
README.md Documentation for custom import batch size and disabling strict validation
pom.xml Updated org.json dependency from version 20231013 to 20250517

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

santigracia and others added 2 commits November 18, 2025 00:13
correcting current import limit

Co-authored-by: Copilot <[email protected]>
We are now enforcing non-empty token for MessageBuilder and import before hitting the server

Co-authored-by: Copilot <[email protected]>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java:1

  • The mLastResponseBody and mLastStatusCode fields are not thread-safe. If multiple threads call deliver() concurrently on the same MixpanelAPI instance, these fields can be overwritten by concurrent requests, leading to incorrect error messages being reported. Consider using ThreadLocal storage or making these local variables passed through the call stack instead of instance fields.
package com.mixpanel.mixpanelapi;

src/demo/java/com/mixpanel/mixpanelapi/demo/MixpanelAPIDemo.java:84

  • The printUsage() documentation still mentions 'Tracking charges' but the trackCharge() method has been deprecated and no longer functions. This line should be updated to reflect that the demo shows the deprecated trackCharge() method (which now only logs an error) or removed entirely.
        System.out.println("  - Tracking charges");

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Changed mConnectTimeoutMillis, mReadTimeoutMillis, and mStrictImportMode to volatile for thread safety. Updated Javadoc for setConnectTimeout and setReadTimeout to clarify thread-safe usage and best practices for concurrent environments.
Updated Javadoc examples
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

santigracia and others added 7 commits November 18, 2025 21:02
[nitpick] The string "utf-8" is used in lowercase

Co-authored-by: Copilot <[email protected]>
Changed mLastResponseBody and mLastStatusCode to volatile to ensure thread-safe access to the last import response data.
Introduces a 90% safety margin to the chunk size limit in PayloadChunker to account for potential differences in serialization size between individual items and the final JSON array. This ensures that serialized chunks remain safely under server-imposed limits.
Enhances MixpanelAPI to capture and log HTTP error response bodies for failed requests, and updates MixpanelServerException to include HTTP status code and response body. This provides more detailed diagnostics for server-side errors and aids debugging of malformed or rejected messages. Adding this to the README.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

2 participants