Setting Global Properties
Define custom properties that automatically attach to every session and event sent from your app, enabling detailed data segmentation in reports.
Global properties let you track any user, app mode, or contextual information you need. For example, in a gaming app, create a "Level" property initialized to "0" that updates as users progress. All sessions and events include this property, allowing you to analyze sessions, event counts, and revenue broken down by user level.
Property Specifications
Limits and Persistence
Understand the constraints and persistence behavior of global properties.
- Maximum Properties: Define up to 5 global properties per app installation
- Persistence: Properties persist between app launches with their most recent values until explicitly unset or the app is uninstalled
- Character Limit: Property names and values can be up to 200 characters long. Longer values are automatically truncated to 200 characters
- Data Availability: Global properties are accessible in user-level exports and postbacks. Contact your Singular customer success manager for updates on aggregate reporting support
Setting Global Properties at Initialization
Configure via SingularConfig
Set global properties during SDK initialization using the
withGlobalProperty
method before calling
Singular.init()
.
Since global properties persist between app launches, properties may
already exist with different values. Use the
overrideExisting
parameter to control whether the new value should override existing values.
// Set global properties during initialization
val config = SingularConfig("SDK_KEY", "SDK_SECRET")
.withGlobalProperty("MyProperty", "MyValue", true)
.withGlobalProperty("AnotherProperty", "AnotherValue", true)
Singular.init(applicationContext, config)
// Set global properties during initialization
SingularConfig config = new SingularConfig("SDK_KEY", "SDK_SECRET")
.withGlobalProperty("MyProperty", "MyValue", true)
.withGlobalProperty("AnotherProperty", "AnotherValue", true);
Singular.init(getApplicationContext(), config);
Method Signature:
public SingularConfig withGlobalProperty(String key, String value, boolean overrideExisting)
Parameters:
- key: Property name (max 200 characters)
- value: Property value (max 200 characters)
- overrideExisting: Whether to override an existing property with the same key
Managing Properties After Initialization
Set Global Property
Add or update a global property at any point during the app's runtime.
// Set a global property after initialization
val result = Singular.setGlobalProperty("MyProperty", "MyValue", true)
if (result) {
Log.d("Singular", "Property set successfully")
} else {
Log.e("Singular", "Failed to set property")
}
// Set a global property after initialization
boolean result = Singular.setGlobalProperty("MyProperty", "MyValue", true);
if (result) {
Log.d("Singular", "Property set successfully");
} else {
Log.e("Singular", "Failed to set property");
}
Method Signature:
public static boolean setGlobalProperty(String key, String value, boolean overrideExisting)
Returns:
true
if the property was set successfully,
false
otherwise
Important:
-
The method returns
falseif thekeyisnullor empty -
The method returns
falseifSingular.init()has not been called yet -
If 5 properties already exist and you attempt to add a new one,
the method returns
false -
If a property with the same key already exists and
overrideExistingisfalse, the value is not replaced and the method returnsfalse -
The
overrideExistingparameter determines whether to replace existing property values - Check the return value to confirm the property was set successfully
Get Global Properties
Retrieve all currently set global properties and their values as a Map.
// Retrieve all global properties
val properties: Map<String, String> = Singular.getGlobalProperties()
// Iterate through properties
properties.forEach { (key, value) ->
Log.d("Singular", "Property: $key = $value")
}
// Retrieve all global properties
Map<String, String> properties = Singular.getGlobalProperties();
// Iterate through properties
for (Map.Entry<String, String> entry : properties.entrySet()) {
Log.d("Singular", "Property: " + entry.getKey() + " = " + entry.getValue());
}
Method Signature:
public static Map<String, String> getGlobalProperties()
Returns: A Map containing all global property key-value pairs
Unset Global Property
Remove a specific global property by its key.
// Remove a specific global property
Singular.unsetGlobalProperty("MyProperty")
// Remove a specific global property
Singular.unsetGlobalProperty("MyProperty");
Method Signature:
public static void unsetGlobalProperty(String key)
Parameters:
- key: The name of the property to remove
Clear All Global Properties
Remove all global properties at once.
// Remove all global properties
Singular.clearGlobalProperties()
// Remove all global properties
Singular.clearGlobalProperties();
Method Signature:
public static void clearGlobalProperties()
Best Practice:
Use
clearGlobalProperties()
when a user logs out or when you need to reset all custom tracking
properties to their default state.
Implementation Example
Complete Usage Pattern
Track app-level and user-specific properties throughout the application lifecycle.
// Initialize SDK with app-level global properties
val config = SingularConfig("SDK_KEY", "SDK_SECRET")
.withGlobalProperty("app_version", BuildConfig.VERSION_NAME, true)
Singular.init(applicationContext, config)
// Set third-party identifier on login
fun onUserLogin(thirdPartyUserId: String) {
val success = Singular.setGlobalProperty("third_party_identifier", thirdPartyUserId, true)
if (success) {
Log.d("Singular", "Third-party identifier set")
}
}
// Clear third-party identifier on logout
fun onUserLogout() {
Singular.unsetGlobalProperty("third_party_identifier")
Log.d("Singular", "Third-party identifier cleared")
}
// Initialize SDK with app-level global properties
SingularConfig config = new SingularConfig("SDK_KEY", "SDK_SECRET")
.withGlobalProperty("app_version", BuildConfig.VERSION_NAME, true);
Singular.init(getApplicationContext(), config);
// Set third-party identifier on login
public void onUserLogin(String thirdPartyUserId) {
boolean success = Singular.setGlobalProperty("third_party_identifier", thirdPartyUserId, true);
if (success) {
Log.d("Singular", "Third-party identifier set");
}
}
// Clear third-party identifier on logout
public void onUserLogout() {
Singular.unsetGlobalProperty("third_party_identifier");
Log.d("Singular", "Third-party identifier cleared");
}
Best Practice:
Sync third-party analytics identifiers
(e.g., Mixpanel distinct_id, Amplitude user_id) to Singular global
properties for unified cross-platform tracking. Set user-specific
identifiers on login and clear them with
unsetGlobalProperty()
on logout. App-level properties
like
app_version
persist across sessions.