Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track any user interaction of an iOS App

How can I track or catch every user interaction of my iOS app? Like pressing an UIButton, UIBarButton, ... any UIControl element.

I know there are hundreds of analytics tools like Google Analytics, Flurry, Appsee and so on, but I want to save these data on my own server.

like image 800
tuvok Avatar asked Jan 28 '26 12:01

tuvok


1 Answers

You can subclass UIApplication:

  • Create an UIApplication Subclass
  • override the sendAction(_ action: Selector, to target: Any?, from sender: Any?, for event: UIEvent?) event method, remember to call the super implementation
  • put an NSLog or other diagnostic code inside the implementation

Example, this will print a log every time an UIButton is pressed:

func sendAction(_ action: Selector, to target: Any?, from sender: Any?, for event: UIEvent?) -> Bool {
    if (sender is UIButton) {
        print("Action: \(NSStringFromSelector(action)) - \(target) - \(sender)")
    }
    return super.sendAction(action, to: target, from: sender, for: event)
}


2017-07-08 14:46:18.270 UIApplicationSubclass[94764:c07] Action: anAction: - <ViewController: 0x76790a0> - <UIRoundedRectButton: 0x767b9b0; frame = (103 66; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x767bad0>>
2017-07-08 14:46:27.378 UIApplicationSubclass[94764:c07] Action: anAction: - <ViewController: 0x76790a0> - <UIRoundedRectButton: 0x767b9b0; frame = (103 66; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x767bad0>>

For objective-c reference click here

like image 170
Abdul Karim Avatar answered Jan 31 '26 05:01

Abdul Karim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!