added iOS source code
[wl-app.git] / iOS / WolneLektury / Screens / Common / WLViewController.swift
diff --git a/iOS/WolneLektury/Screens/Common/WLViewController.swift b/iOS/WolneLektury/Screens/Common/WLViewController.swift
new file mode 100644 (file)
index 0000000..8df91fa
--- /dev/null
@@ -0,0 +1,54 @@
+//
+//  WLViewController.swift
+//  WolneLektury
+//
+//  Created by Pawel Dabrowski on 25/09/2018.
+//  Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
+//
+
+import UIKit
+import MatomoTracker
+
+class WLViewController: UIViewController {
+
+    func name() -> String {
+        
+        return String(describing: type(of: self)).replacingOccurrences(of: "ViewController", with: "")
+    }
+    
+    func parentNames() -> [String] {
+        var namesList = [String]()
+        if let controller = self.parent as? WLViewController {
+            namesList.append(contentsOf: controller.parentNames())
+            namesList.append(name())
+        }
+        else if let controller = self.parent as? UINavigationController {
+            for vc in controller.childViewControllers{
+                if let vc = vc as? WLViewController {
+                    namesList.append(vc.name())
+                }
+            }
+        }
+        else {
+            namesList.append(name())
+        }
+        return namesList
+    }
+    
+    func trackScreen() {
+        
+        print("trackScreen \(parentNames())")
+        MatomoTracker.shared.track(view: parentNames())
+    }
+    
+    override func viewDidLoad() {
+        super.viewDidLoad()
+        trackScreen()
+    }
+
+    override func didReceiveMemoryWarning() {
+        super.didReceiveMemoryWarning()
+        // Dispose of any resources that can be recreated.
+    }
+    
+}