Skip to content

Commit

Permalink
Renamed the visitorId property to userId to be more inline with the D…
Browse files Browse the repository at this point in the history
…ocumentation. (#268)
  • Loading branch information
brototyp committed Aug 17, 2018
1 parent 790ed7d commit 971510e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions 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)

Expand Down
8 changes: 4 additions & 4 deletions Example/ios/iOS Example/UserIDViewController.swift
Expand Up @@ -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()
}

Expand All @@ -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
}
Expand Down
12 changes: 11 additions & 1 deletion MatomoTracker/MatomoTracker.swift
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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.
Expand Down

0 comments on commit 971510e

Please sign in to comment.