-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/180 custom visitor ID #181
Changes from 6 commits
d72a69a
55486ec
07f063e
365de38
e5f5077
aaad1d2
a9e9bf3
ff45fb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
import PiwikTracker | ||
|
||
class UserIDViewController: UIViewController { | ||
@IBOutlet weak var userIDTextField: UITextField! | ||
@IBOutlet weak var signinButton: UIButton! | ||
@IBOutlet weak var signoutButton: UIButton! | ||
|
||
@IBAction func signinAction(_ sender: UIButton) { | ||
if (self.userIDTextField.text != nil) && (self.userIDTextField.text?.characters.count)! > 0 { | ||
PiwikTracker.shared?.visitorId = self.userIDTextField.text | ||
toggleState() | ||
} | ||
} | ||
|
||
@IBAction func signOutAction(_ sender: UIButton) { | ||
PiwikTracker.shared?.visitorId = nil | ||
toggleState() | ||
} | ||
|
||
override func viewDidLoad() { | ||
toggleState() | ||
} | ||
|
||
private func toggleState() { | ||
self.userIDTextField.text = PiwikTracker.shared?.visitorId | ||
|
||
self.signinButton.isEnabled = !isVisitorIdValid() | ||
self.signoutButton.isEnabled = !self.signinButton.isEnabled | ||
} | ||
|
||
private func isVisitorIdValid() -> Bool { | ||
let currentVisitorId = PiwikTracker.shared?.visitorId | ||
|
||
return (currentVisitorId != nil) && (currentVisitorId?.characters.count)! > 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,10 +60,20 @@ internal struct PiwikUserDefaults { | |
|
||
var clientId: String? { | ||
get { | ||
return userDefaults.string(forKey: PiwikUserDefaults.Key.visitorID) | ||
return userDefaults.string(forKey: PiwikUserDefaults.Key.clientID) | ||
} | ||
set { | ||
userDefaults.setValue(newValue, forKey: PiwikUserDefaults.Key.visitorID) | ||
userDefaults.setValue(newValue, forKey: PiwikUserDefaults.Key.clientID) | ||
userDefaults.synchronize() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you change it this way, it will change the behavior of all old implementations. For all old Implementations the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I've adjusted this in a9e9bf3. I left my changes for using the correct "key name", but changing what value the key is using so it's using the old one. This should retain the existing functionality but be more clear in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think that's the best solution in this case. It's a bit of a pity that it got introduced in the first place. Thanks for changing it this way. |
||
|
||
var visitorId: String? { | ||
get { | ||
return userDefaults.string(forKey: PiwikUserDefaults.Key.visitorID); | ||
} | ||
set { | ||
userDefaults.setValue(newValue, forKey: PiwikUserDefaults.Key.visitorID); | ||
userDefaults.synchronize() | ||
} | ||
} | ||
|
@@ -75,6 +85,7 @@ extension PiwikUserDefaults { | |
static let currentVisitTimestamp = "PiwikCurrentVisitTimestampKey" | ||
static let previousVistsTimestamp = "PiwikPreviousVistsTimestampKey" | ||
static let firstVistsTimestamp = "PiwikFirstVistsTimestampKey" | ||
static let clientID = "PiwikClientIDKey" | ||
static let visitorID = "PiwikVisitorIDKey" | ||
static let optOut = "PiwikOptOutKey" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for adding this to the Example Application!