iOS SDK - Setting Global Properties

Setting Global Properties

The Singular SDK lets you define custom properties to be sent to the Singular servers along with every session and event sent from the app. These properties can represent any information you want about the user, the app mode/status, or anything else.

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.

Use Cases

Some use cases for global properties are:

  • Pass an identifier from a third-party SDK and then use it in a postback from Singular to said third party for matching purposes.
  • In 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.

Notes:

  • Global properties are currently reflected in Singular's user-level event logs (see Exporting Attribution Logs) and in postbacks. Support for global properties in Singular's aggregate reporting (the Reports page or the reporting API) will be added in the future. If you have questions about this feature or are interested in updates to global properties support, contact your Singular customer success manager.
  • 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.

Setting Global Properties through the Config Object

To set global properties before initializing the SDK, use the setGlobalProperty method in the Config object.

Note that since global properties and their values persist between app runs, the property 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.

setGlobalProperty Method
Description Set a global property.
Signature (void)setGlobalProperty:(NSString*)key withValue:(NSString*)value overrideExisting:(BOOL)overrideExisiting;
Usage Example
SwiftObjective-C
func getConfig() -> SingularConfig? {         
  // (Optional) Get 3rd-party identifiers to set in Global Properties:     

  // If 3rd-party SDKs are providing any identifiers to Singular, the

  // respective SDK must be initialized before Singular.     

  let thirdPartyKey = "anonymousID"     
  let thirdPartyID = "2ed20738-059d-42b5-ab80-5aa0c530e3e1"     
  
  // Singular Config Options     

  guard let config = SingularConfig(apiKey: Constants.APIKEY, 
    andSecret: Constants.SECRET) else {
      return nil
      }
  //...     
  // Using Singular Global Properties feature to capture third party identifiers

  config.setGlobalProperty(thirdPartyKey, withValue: thirdPartyID, overrideExisting: true)     
  //...
  return config 
}

Setting Global Properties After Initialization

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

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.
setGlobalProperty Method
Description Set a global property to a given value.
Signature (BOOL) setGlobalProperty:(NSString*)key andValue:(NSString*)value overrideExisting:(BOOL)overrideExisting
Usage Example
SwiftObjective-C
var result = Singular.setGlobalProperty("propertyName",
  andValue: "propertyValue", overrideExisting: true)
getGlobalProperties Method
Description Retrieve all the global properties and their current values as a Map.
Signature NSDictionary*) getGlobalProperties
Usage Example
SwiftObjective-C
var globalProperties = Singular.getGlobalProperties()
unsetGlobalProperty Method
Description Remove a global property.
Signature (void) unsetGlobalProperty:(NSString*)key
Usage Example
SwiftObjective-C
Singular.unsetGlobalProperty("propertyName")
clearGlobalProperties Method
Description Remove all global properties.
Signature (void) clearGlobalProperties
Usage Example
SwiftObjective-C
Singular.clearGlobalProperties()