Setting Global Properties

Setting Global Properties

The Singular SDK lets you define additional custom properties to send to the Singular servers with every session and event sent from the app. These properties can represent any information you want about the user, the app mode or status, or anything else. Once you set these properties, they are available as dimensions in your reports and you can use them to break down your data.

For example, if you have a gaming app, you can define a property called "Level" and set it initially to "0". Any session and event sent from the app will be sent with "Level": "0". Once the user levels up you reset the property to "1" and so on. You can then get your reports, including sessions, event counts, and revenue data, broken down by user level.

  • You can define up to 5 global properties.
  • They persist between app runs (with the latest value you gave them) until you unset them or the user uninstalls the app.
  • Each property name and value can be up to 200 characters long. If you pass a longer property name or value, it will be truncated to 200 characters.
  • Global properties are accessible and available in user-level exports and postbacks. In the future, aggregate reporting support will be added. Let your Singular customer success manager know if you have any questions, or are interested in updates to global properties support!

Setting Global Properties through SingularConfig

You can use the withGlobalProperty method to set global properties through SingularConfig before initializing the SDK.

Note that since global properties and their values persist between app runs, the property that you are setting may already be set to a different value. Use the overrideExisting parameter to tell the SDK whether to override an existing property with the new value or not.

withGlobalProperty Method 
Description Set a global property.
Signature .withGlobalProperty(String key, String value, boolean overrideExisting)
Usage Example
// Set two global properties and override any existing values
SingularConfig config = new SingularConfig("SDK KEY", "SDK SECRET")
  .withGlobalProperty(“MyProperty”, “MyValue”, true)
  .withGlobalProperty(“AnotherProperty”, “AnotherValue”, true);

Setting Global Properties After Initialization

Use the following methods to set, unset, and retrieve global properties at any time in the app's run.

Singular.setGlobalProperty Method
Description

Set a global property to a given value.

Notes:

  • If the property does not exist yet, and there are already 5 other global properties, the property will not be added.
  • If the property has already been set, the overrideExisting parameter determines whether the existing value will be overridden.
  • The method returns true if the property was set successfully or false otherwise.
Signature public static bool setGlobalProperty(String key, String value, boolean overrideExisting)
Usage Example
boolean result = Singular.setGlobalProperty(“MyProperty”, “MyValue”, true);
Singular.getGlobalProperties Method
Description Retrieve all the global properties and their current values as a Map.
Signature public static Map<String, String> getGlobalProperties()
Usage Example
Map<String, String> map = Singular.getGlobalProperties();
Singular.unsetGlobalProperty Method
Description Remove a global property.
Signature public static void unsetGlobalProperty(String key)
Usage Example
Singular.unsetGlobalProperty(“MyProperty”);
Singular.clearGlobalProperties Method
Description Remove all global properties.
Signature public static void clearGlobalProperties()
Usage Example
Singular.clearGlobalProperties();