From 98937d39f81d5bd8a6d9f6cd6e36b997e8898900 Mon Sep 17 00:00:00 2001 From: Cornelius Horstmann Date: Sat, 3 Jun 2017 15:59:27 +0200 Subject: [PATCH] Added a way of setting customTrackingParameters to an Event and tracking custom Events. --- Example/Example.xcodeproj/project.pbxproj | 4 + .../CustomEventsViewController.swift | 24 ++++ .../iOS Example/OptOutViewController.swift | 6 +- .../en.lproj/MainStoryboard.storyboard | 116 ++++++++++++++---- PiwikTracker/Event.swift | 52 +++++++- PiwikTracker/PiwikTracker.swift | 42 +++---- PiwikTracker/URLSessionDispatcher.swift | 3 +- Podfile.lock | 8 +- 8 files changed, 198 insertions(+), 57 deletions(-) create mode 100644 Example/iOS Example/CustomEventsViewController.swift diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 61f43b35..f57823d3 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 1F72DA6F1E61ECAF00EFF764 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F72DA6E1E61ECAF00EFF764 /* AppDelegate.swift */; }; 1F72DA711E62E55200EFF764 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F72DA701E62E55200EFF764 /* MenuViewController.swift */; }; 1F72DA731E62E78E00EFF764 /* ConfigurationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F72DA721E62E78E00EFF764 /* ConfigurationViewController.swift */; }; + 1F8D35951EE2F4DC0058940F /* CustomEventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F8D35941EE2F4DC0058940F /* CustomEventsViewController.swift */; }; 1FEF8EFB1EDCB1B3001D907F /* OptOutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FEF8EFA1EDCB1B3001D907F /* OptOutViewController.swift */; }; CD93EC8C17E76E290062BE20 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD1EA93417B0DA4400F63E14 /* UIKit.framework */; }; CD93EC8D17E76E290062BE20 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD10FABF17B0378D0012BE50 /* Foundation.framework */; }; @@ -76,6 +77,7 @@ 1F72DA6E1E61ECAF00EFF764 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 1F72DA701E62E55200EFF764 /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; 1F72DA721E62E78E00EFF764 /* ConfigurationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationViewController.swift; sourceTree = ""; }; + 1F8D35941EE2F4DC0058940F /* CustomEventsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomEventsViewController.swift; sourceTree = ""; }; 1FEF8EFA1EDCB1B3001D907F /* OptOutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptOutViewController.swift; sourceTree = ""; }; 3AEBBD63B45D1F968424585B /* libPods-iosafnetworking2.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-iosafnetworking2.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 5D7BD4274A519A9E5A07FAB5 /* Pods-example-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-example-ios.release.xcconfig"; path = "../Pods/Target Support Files/Pods-example-ios/Pods-example-ios.release.xcconfig"; sourceTree = ""; }; @@ -207,6 +209,7 @@ 1F03BC9A1E86CF770002F0AD /* ScreenViewController.swift */, 1F03BC9C1E86CFC30002F0AD /* SecondScreenViewController.swift */, 1FEF8EFA1EDCB1B3001D907F /* OptOutViewController.swift */, + 1F8D35941EE2F4DC0058940F /* CustomEventsViewController.swift */, CD5C9813193E65CF00A8A801 /* CampaignViewController.h */, CD5C9814193E65CF00A8A801 /* CampaignViewController.m */, CDD56BFC19F587A100816D5A /* ContentTrackerViewController.h */, @@ -406,6 +409,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1F8D35951EE2F4DC0058940F /* CustomEventsViewController.swift in Sources */, 1F03BC9D1E86CFC30002F0AD /* SecondScreenViewController.swift in Sources */, 1F72DA6F1E61ECAF00EFF764 /* AppDelegate.swift in Sources */, 1F03BC991E86CC7E0002F0AD /* EventsViewController.swift in Sources */, diff --git a/Example/iOS Example/CustomEventsViewController.swift b/Example/iOS Example/CustomEventsViewController.swift new file mode 100644 index 00000000..76a09aa6 --- /dev/null +++ b/Example/iOS Example/CustomEventsViewController.swift @@ -0,0 +1,24 @@ +// +// CustomEventsViewController.swift +// Example +// +// Created by Cornelius Horstmann on 03.06.17. +// Copyright © 2017 Mattias Levin. All rights reserved. +// + +import UIKit +import PiwikTracker + +class CustomEventsViewController: UIViewController { + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + PiwikTracker.shared?.track(view: ["menu","custom event"]) + } + + @IBAction func trackCustomEventButtonTapped(_ sender: Any) { + guard let tracker = PiwikTracker.shared else { return } + let downloadURL = URL(string: "https://builds.piwik.org/piwik.zip")! + let event = tracker.event().setting(url: downloadURL).setting(customTrackingParameters: ["download":downloadURL.absoluteString]) + tracker.track(event) + } +} diff --git a/Example/iOS Example/OptOutViewController.swift b/Example/iOS Example/OptOutViewController.swift index 9a6887ff..d8a3c32c 100644 --- a/Example/iOS Example/OptOutViewController.swift +++ b/Example/iOS Example/OptOutViewController.swift @@ -5,16 +5,16 @@ class OptOutViewController: UIViewController { @IBOutlet weak var optOutSwitch: UISwitch! @IBAction func optOutSwitchChanged(_ sender: Any) { - Tracker.shared?.isOptedOut = optOutSwitch.isOn + PiwikTracker.shared?.isOptedOut = optOutSwitch.isOn } override func viewDidLoad() { super.viewDidLoad() - optOutSwitch.isOn = Tracker.shared?.isOptedOut ?? false + optOutSwitch.isOn = PiwikTracker.shared?.isOptedOut ?? false } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - Tracker.shared?.track(view: ["menu","opt out"]) + PiwikTracker.shared?.track(view: ["menu","opt out"]) } } diff --git a/Example/iOS Example/en.lproj/MainStoryboard.storyboard b/Example/iOS Example/en.lproj/MainStoryboard.storyboard index 9d69a04b..83b22c69 100644 --- a/Example/iOS Example/en.lproj/MainStoryboard.storyboard +++ b/Example/iOS Example/en.lproj/MainStoryboard.storyboard @@ -1,5 +1,5 @@ - + @@ -41,7 +41,7 @@ - +