I want Swift to put the tracking code anywhere I can call it.

Asked 2 years ago, Updated 2 years ago, 73 views

I would like to place GA's screen tracking code in a location that is always called (e.g., UIVeiwController) when I view each view, so that I can dynamically get the class name, but where is the code actually correct?

If possible, I would appreciate it if you could provide me with a code that would be a sample.

Thank you for your cooperation.

swift ios

2022-09-30 21:27

1 Answers

How about creating one parent class and inheriting the others?

class MYBaseViewController:UIViewController 
{
    override func viewWillAppear (animated:Bool) 
    {
        super.viewWillAppear(animated)

        // GA screen tracking code here
    }
}

For each class:

class MYViewController:MYBaseViewController 
{
    override func viewWillAppear (animated:Bool) 
    {
        super.viewWillAppear(animated)// Don't forget this.

        // Write the code as usual
    }
}

If you implement it with extension, it will be like adding a method, so
I think it's still something you have to call manually.


2022-09-30 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.