Complete reference for all User Analytics SDK methods and classes.
The main class for interacting with the User Analytics SDK.
com.analytics.analyticstracker.AnalyticsTracker
import com.analytics.analyticstracker.AnalyticsTracker;
Initializes the SDK with custom server URL and API key.
Parameters:
baseUrl
(String): The analytics server URLapiKey
(String): Your unique API key from the dashboardExample:
AnalyticsTracker.init("https://d1xb34m3k0zeus.cloudfront.net/", "ak_your_api_key");
Notes:
onCreate()
of your main activityak_
followed by alphanumeric charactersInitializes the SDK with API key only (uses default server URL).
Parameters:
apiKey
(String): Your unique API keyExample:
AnalyticsTracker.init("ak_your_api_key");
Note: This method uses a default base URL. Use the two-parameter version for production.
Tracks a custom user event with properties.
Parameters:
userId
(String): Unique identifier for the useractionName
(String): Name of the action/eventproperties
(Map<String, Object>): Additional event dataExample:
Map<String, Object> properties = new HashMap<>();
properties.put("category", "ספורט");
properties.put("subcategory", "כדורגל");
properties.put("item", "כריסטיאנו רונאלדו");
AnalyticsTracker.trackEvent("user123", "click_item", properties);
Common Event Names:
app_opened
- App launchclick_category
- Category selectionclick_subcategory
- Subcategory selectionclick_item
- Interest item selectionprofile_viewed
- Profile screen viewedprofile_updated
- Profile information updatedProperty Types:
Starts tracking time spent on a screen.
Parameters:
screenName
(String): Name of the screen/activityExample:
@Override
protected void onResume() {
super.onResume();
AnalyticsTracker.startScreen("MainActivity");
}
Best Practices:
onResume()
methodEnds screen time tracking and sends data to server.
Parameters:
userId
(String): Unique identifier for the userExample:
@Override
protected void onPause() {
super.onPause();
AnalyticsTracker.endScreen("user123");
}
Best Practices:
onPause()
methodstartScreen()
Manually track screen time with specific timestamps.
Parameters:
userId
(String): User identifierscreenName
(String): Screen namestartTimeMillis
(long): Start timestamp in millisecondsendTimeMillis
(long): End timestamp in millisecondsdurationMillis
(long): Duration in millisecondsExample:
long startTime = System.currentTimeMillis();
// ... user interaction ...
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
AnalyticsTracker.trackScreenTime("user123", "GameScreen", startTime, endTime, duration);
Note: This method is for advanced use cases. Use startScreen()
/endScreen()
for normal tracking.
Authenticates a user with the analytics system.
Parameters:
request
(LoginRequest): Login credentialscallback
(CallbackExample:
LoginRequest loginRequest = new LoginRequest("user@myinterest.com", "password");
AnalyticsTracker.loginUser(loginRequest, new Callback<AuthResponse>() {
@Override
public void onResponse(Call<AuthResponse> call, Response<AuthResponse> response) {
if (response.isSuccessful()) {
AuthResponse authResponse = response.body();
// Handle successful login
}
}
@Override
public void onFailure(Call<AuthResponse> call, Throwable t) {
// Handle login error
}
});
Updates user’s name information.
Parameters:
userId
(String): User identifierfirstName
(String): User’s first namelastName
(String): User’s last namecallback
(CallbackExample:
AnalyticsTracker.updateUserName("user123", "John", "Doe", new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) {
// Name updated successfully
}
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
// Handle error
}
});
Represents a user action event.
Fields:
userId
(String): User identifieractionName
(String): Action nametimestamp
(String): ISO timestampproperties
(Map<String, Object>): Event propertiesapiKey
(String): API keyRepresents screen time data.
Fields:
userId
(String): User identifierscreenName
(String): Screen namedurationMillis
(long): Duration in millisecondsstartTime
(String): Start timestampendTime
(String): End timestampapiKey
(String): API keyLogin request data.
Fields:
email
(String): User emailpassword
(String): User passwordAuthentication response.
Fields:
token
(String): JWT tokenuserId
(String): User IDemail
(String): User emailThe SDK handles errors gracefully:
The SDK uses Android’s Log system:
Log.d("AnalyticsTracker", "Event sent successfully");
Log.e("AnalyticsTracker", "Network error occurred");
Log Tags:
AnalyticsTracker
- Main SDK operationsApiClient
- Network operations// Good: Consistent user ID
String userId = UserManager.getCurrentUserId();
AnalyticsTracker.trackEvent(userId, "action", properties);
// Bad: Hardcoded or random IDs
AnalyticsTracker.trackEvent("user123", "action", properties);
// Good: Descriptive, consistent naming
AnalyticsTracker.trackEvent(userId, "click_category", properties);
// Bad: Vague or inconsistent naming
AnalyticsTracker.trackEvent(userId, "click", properties);
// Good: Structured, meaningful properties
Map<String, Object> properties = new HashMap<>();
properties.put("category", "ספורט");
properties.put("subcategory", "כדורגל");
properties.put("item", "כריסטיאנו רונאלדו");
properties.put("position", 0);
// Bad: Unstructured or meaningless properties
Map<String, Object> properties = new HashMap<>();
properties.put("data", "some_value");
Common error scenarios and their handling:
Error | Description | Solution |
---|---|---|
API Key not initialized |
SDK not initialized | Call init() first |
Network error |
Connection failed | Check internet connection |
Invalid API key |
Wrong or expired key | Verify key in dashboard |
Server error 500 |
Backend issue | Contact support |
For more examples, see Examples Documentation