All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deque.networking.analytics.AmplitudeClient.kt Maven / Gradle / Ivy

The newest version!
package com.deque.networking.analytics

import com.deque.networking.models.DequeRetrofitBuilder

internal class AmplitudeClient(
    private val apiKey: String,
    private val baseUrl: String
) {
    private val amplitudeInterface: AmplitudeInterface = DequeRetrofitBuilder(baseUrl)
        .client(AmplitudeInterface::class.java)

    private val sessionId by lazy { System.currentTimeMillis() }

    suspend fun sendEvent(
        eventType: AmplitudeEventType,
        eventInfoProps: AmplitudeEventInfoProps? = null,
        eventProps: AmplitudeEventProps? = null
    ): Result {
        return amplitudeInterface.sendEvent(
            AmplitudeData(
                api_key = apiKey,
                events = listOf(
                    AmplitudeEvent(
                        user_id = AnalyticsService.userId,
                        event_type = eventType.eventName,
                        session_id = sessionId,
                        event_properties = eventProps,
                        os_name = eventInfoProps?.os_name,
                        os_version = eventInfoProps?.os_version,
                        device_brand = eventInfoProps?.device_brand,
                        device_manufacturer = eventInfoProps?.device_manufacturer,
                        device_model = eventInfoProps?.device_model,
                        time = eventInfoProps?.time ?: System.currentTimeMillis()
                    )
                )
            )
        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy