-
Notifications
You must be signed in to change notification settings - Fork 164
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
Add reset method to MatomoTracker #418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -468,3 +468,24 @@ extension MatomoTracker { | |
/// The version of the Matomo SDKs | ||
@objc public static let sdkVersion = "7.3" | ||
} | ||
|
||
extension MatomoTracker { | ||
/// Resets all session, visitor and campaign information. | ||
/// | ||
/// Dispatches events before restting itself. | ||
/// After calling this method this instance behaves like the app has been freshly installed. | ||
public func reset() { | ||
dispatch() | ||
|
||
matomoUserDefaults.reset() | ||
|
||
visitor = Visitor.current(in: matomoUserDefaults) | ||
session = Session.current(in: matomoUserDefaults) | ||
dimensions = [] | ||
customVariables = [] | ||
campaignName = nil | ||
campaignKeyword = nil | ||
|
||
startNewSession() | ||
} | ||
} | ||
Comment on lines
+472
to
+491
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. With this function we do have the risk, that if we add any properties, we forget to reset them in here as well. Unfortunately I don't have a great idea how to prevent this. I still wanted to bring this up here in case you have an idea. One option would certainly be to replace the instance of |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,18 @@ internal struct MatomoUserDefaults { | |
userDefaults.set(newValue, forKey: MatomoUserDefaults.Key.lastOrder) | ||
} | ||
} | ||
|
||
func reset() { | ||
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. I was thinking about the term |
||
userDefaults.removeObject(forKey: Key.totalNumberOfVisits) | ||
userDefaults.removeObject(forKey: Key.currentVisitTimestamp) | ||
userDefaults.removeObject(forKey: Key.previousVistsTimestamp) | ||
userDefaults.removeObject(forKey: Key.firstVistsTimestamp) | ||
userDefaults.removeObject(forKey: Key.clientID) | ||
userDefaults.removeObject(forKey: Key.forcedVisitorID) | ||
userDefaults.removeObject(forKey: Key.visitorUserID) | ||
userDefaults.removeObject(forKey: Key.optOut) | ||
userDefaults.removeObject(forKey: Key.lastOrder) | ||
Comment on lines
+104
to
+112
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. I could see the risk, once we add a new property that is stored in the user defaults, that we forget to remove it here as well. What do you think about changing the |
||
} | ||
} | ||
|
||
extension MatomoUserDefaults { | ||
|
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.
I think, first think in this function, we should ensure we are running on the main thread.