typesense / typesense-java

Java client for Typesense
https://typesense.org/docs/latest/api/
Apache License 2.0
60 stars 29 forks source link

feat(analytics): add analytics rules and events support #72

Closed tharropoulos closed 3 weeks ago

tharropoulos commented 4 weeks ago

Change Summary

Rationale

The Typesense server provides analytics capabilities through its /analytics endpoints, but these features were not accessible through the Java client. Users needed to track search analytics and user interactions but had to implement their own HTTP calls or workarounds.

This PR adds complete support for Analytics Rules and Events.

Changes

Added Features:

  1. New Analytics Management (Analytics.java):

    • Central class for managing analytics operations
    • Provides access to rules and events APIs
  2. Analytics Rules Support (AnalyticsRules.java, AnalyticsRule.java):

    • create(): Create new analytics collection rules
    • upsert(): Create or update existing rules
    • retrieve(): Get single or all analytics rules
    • delete(): Remove analytics rules
    • Complete parameter support for rule configuration
  3. Analytics Events Tracking (AnalyticsEvents.java):

    • create(): Track custom analytics events

Code Changes:

  1. In Client.java:

    • Added analytics field and getter
    • Integrated analytics support in client initialization
  2. In Helper.java:

    • Added test support methods for analytics
    • Enhanced teardown to clean analytics rules
    • Added test collection creation for analytics data

Documentation Updates:

  1. In README.md:
    • Added comprehensive examples for analytics rules
    • Added examples for tracking custom events
    • Added code samples with use cases

Tests:

  1. New Test Classes:
    • AnalyticsRulesTest.java: Complete test coverage for rules API
    • AnalyticsEventsTest.java: Event creation and validation tests
    • Integration tests with existing collections

Context

This implementation addresses and closes the feature request in #71 by @danipenaperez for analytics support in the Java client. It provides a complete solution for both analytics rules and events tracking, giving users the full power of Typesense analytics.

The changes follow the existing client architecture patterns and include comprehensive tests and documentation to ensure reliable usage.

PR Checklist