diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a9f451d..39fc90cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +* **improvement** Renamed the `visitorId` property to `userId` to be more inline with the Documentation. [#258](https://github.com/matomo-org/matomo-sdk-ios/issues/258) * **bugfix** Fixed an issue where `trackSearch` called from Objective-C would end in an infinite loop. [#263](https://github.com/matomo-org/matomo-sdk-ios/issues/263) * **bugfix** Fixed an issue on Objective-C project where swift version was't set. [#260](https://github.com/matomo-org/matomo-sdk-ios/issues/260) diff --git a/Example/ios/iOS Example/UserIDViewController.swift b/Example/ios/iOS Example/UserIDViewController.swift index f946ecf4..5d177f3e 100644 --- a/Example/ios/iOS Example/UserIDViewController.swift +++ b/Example/ios/iOS Example/UserIDViewController.swift @@ -8,13 +8,13 @@ class UserIDViewController: UIViewController { @IBAction func signinAction(_ sender: UIButton) { if (self.userIDTextField.text != nil) && (self.userIDTextField.text?.count)! > 0 { - MatomoTracker.shared.visitorId = self.userIDTextField.text + MatomoTracker.shared.userId = self.userIDTextField.text toggleState() } } @IBAction func signOutAction(_ sender: UIButton) { - MatomoTracker.shared.visitorId = nil + MatomoTracker.shared.userId = nil toggleState() } @@ -28,14 +28,14 @@ class UserIDViewController: UIViewController { } private func toggleState() { - self.userIDTextField.text = MatomoTracker.shared.visitorId + self.userIDTextField.text = MatomoTracker.shared.userId self.signinButton.isEnabled = !isVisitorIdValid() self.signoutButton.isEnabled = !self.signinButton.isEnabled } private func isVisitorIdValid() -> Bool { - let currentVisitorId = MatomoTracker.shared.visitorId + let currentVisitorId = MatomoTracker.shared.userId return (currentVisitorId != nil) && (currentVisitorId?.count)! > 0 } diff --git a/MatomoTracker/MatomoTracker.swift b/MatomoTracker/MatomoTracker.swift index 275f4ee9..69e76a5e 100644 --- a/MatomoTracker/MatomoTracker.swift +++ b/MatomoTracker/MatomoTracker.swift @@ -19,7 +19,7 @@ final public class MatomoTracker: NSObject { /// Will be used to associate all future events with a given userID. This property /// is persisted between app launches. - @objc public var visitorId: String? { + @objc public var userId: String? { get { return matomoUserDefaults.visitorUserId } @@ -29,6 +29,16 @@ final public class MatomoTracker: NSObject { } } + @available(*, deprecated, message: "use userId instead") + @objc public var visitorId: String? { + get { + return userId + } + set { + userId = newValue + } + } + internal var matomoUserDefaults: MatomoUserDefaults private let dispatcher: Dispatcher private var queue: Queue diff --git a/README.md b/README.md index 202491ef..3cba3af6 100644 --- a/README.md +++ b/README.md @@ -114,10 +114,10 @@ Dimensions in the Visit Scope will be sent along every Page View or Event. Custo ### Custom User ID -To add a [custom User ID](https://matomo.org/docs/user-id/), simply set the value you'd like to use on the `visitorId` field of the tracker: +To add a [custom User ID](https://matomo.org/docs/user-id/), simply set the value you'd like to use on the `userId` field of the tracker: ```Swift -matomoTracker.visitorId = "coolUsername123" +matomoTracker.userId = "coolUsername123" ``` All future events being tracked by the SDK will be associated with this userID, as opposed to the default UUID created for each Visitor.