Create a Data Collection Action

In some cases when you trigger an action, you might not want to alter your site's content while still retaining the customer data involved with the action. In these cases, you can perform a data collection action.

You can set up a handler for a data collection action by using two methods. The addEvents method defines the events that can trigger the action. The getActionsData method is then used as the trigger and requests the decision based on the defined events. getActionsData then returns a JSON object containing customer data.

While this data does not affect your site's content, you can use it for other cases elsewhere in code.

addEvent

This method records a local event in the defined context.

addEvent(context: <ContextEnum>, event: <MEvent?>)

Parameters:

  • context is name of the event. (Required)
  • event is the event data. (Required)

getActionsData

This method sends the defined events to Monetate to trigger an experience. If the events fulfill the WHO settings of an experience, then that experience is triggered. A JSON object containing the experience response is then returned.

getActionsData(requestId: <String>, includeReporting: <Bool>, arrActionTypes: <[String]>) 

Parameters:

  • requestID is the request ID for the API.
  • includeReporting indicates whether the response will have impression reporting data.
  • arrActionTypes is the types of action you want to request. You can specify multiple actions in an array to handle.

Code Example

objPersonalization.getActionsData(requestId: "123456", includeReporting: false, arrActionTypes:["monetate:action:DataCollection"]).on{res in 
  if res.status==200 {
    self.handleRecommendations(res: res)
  } else {
  }
 }
}

Full Code Example

Complete code example blocks are listed below.

import MarqueeLabel
import UIKit
import monetate_ios_sdk

class CategoryViewController: UIViewController {
  final var objPersonalization = Personalization(
    account: Account(
      instance: "p", domain: "localhost.org", name: "a-701b337c", shortname: "localhost"),
    user: User(deviceId: "62bd2e2d-213d-463f-83bb-12c0b2530a14"))
  override func viewDidLoad() {
    super.viewDidLoad()
  }
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    dataCollectionEvent()
  }
  func dataCollectionEvent() {
    objPersonalization.addEvent(context: .PageView, event: PageView(pageType: "Homepage", path: "n/a", url: "n/a", categories: [], breadcrumbs: []))
     
    objPersonalization.getActionsData(requestId: "test_request_id", includeReporting: true, arrActionTypes: ["monetate:action:DataCollection"]).on { (res) in
      if res.status == 200 {
        let data = JSON(res.data)
        print(data)
        self.handleAction(res: res)
      } else {
      }
    }
  }
}