Skip to main content

Tracking Events

Nudge provides a track method to track user interactions in your application. You can also send event properties with the track method.

Nudge.getInstance().track(
event: String,
properties: [String : Any]?,
completion: (Result<Bool, any Error>) -> Void
)
warning

Event name, event properties, and user properties all follow this regex : ^[a-z][a-z0-9_]99$

  • Only small alphabets, numbers and underscore (_) are allowed
  • Name cannot start with number, it needs to start with an alphabet only
  • The name should be between 2 and 99 characters in length
  • If any capital letter is sent, it will be converted to small case

The completion handler is optional but, if provided, it will be called once the event tracking process is complete. On success, it returns a Bool value (true) indicating that the event was tracked successfully. If something goes wrong, it returns an Error.

var props: [String: Any] = ["price": 150, "category": "food"]
Nudge.getInstance().track(
event: "click_button",
properties: props
completion: { result in
switch result {
case .success(let success):
if success {
print("Event tracked successfully.")
}
case .failure(let error):
// Handle the error accordingly.
print("Error tracking event: \(error)")
}
}
)