Skip to content

Sending arbitrary data when the user takes an action.

André Herculano edited this page Aug 28, 2020 · 4 revisions

Publisher Data

Sourcepoint's endpoints allow for consent information to be retrieved programatically via APIs. Some times, you might want to send up some piece of information to our servers when the user takes an action, so you can retrieve it when querying our consent APIs/logs.

You can do that by mutating the action: GDPRAction object during the onAction consent delegate method. Example:

// a class that implements GDPRConsentDelegate
func onAction(_ action: GDPRAction) {
    action.publisherData = [
      "myUserId": try? SPGDPRArbitraryJson("abcd"),
      "someOtherInfo": try? SPGDPRArbitraryJson([1, 2, 3])
    ]
}

The SDK will send an object encoding your data in the shape of:

{
  "pubData": {
    "myUserId": "abcd",
    "someOtherInfo": [1, 2, 3]
  }
}

Understanding SPGDPRArbitraryJson

The SPGDPRArbitraryJson encapsulates the values supported by a valid JSON. Being them, primitive types, array of primitive types, null (nil) or a dictionary of [String: SPGDPRArbitraryJson].

The publisherData attribute of GDPRAction is of type [String: SPGDPRArbitraryJson?]? to enforce the data being encoded as an JSON object rather than just a primitive type.