Skip to content
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

Adds cdt parameter to tracking query items #301

Merged
merged 3 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
* **improvement** Added `cdt` query item in addition to `h`/`m`/`s` values [#301] (https://github.com/matomo-org/matomo-sdk-ios/pull/301)
* **improvement** Updated to Swift 5.0 and Xcode 10.3 tools version. [#306](https://github.com/matomo-org/matomo-sdk-ios/pull/306)
* **change** Dropped support for iOS 8 and 9. [#306](https://github.com/matomo-org/matomo-sdk-ios/pull/306)

Expand Down
23 changes: 23 additions & 0 deletions MatomoTracker/EventAPISerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fileprivate extension Event {
URLQueryItem(name: "h", value: DateFormatter.hourDateFormatter.string(from: date)),
URLQueryItem(name: "m", value: DateFormatter.minuteDateFormatter.string(from: date)),
URLQueryItem(name: "s", value: DateFormatter.secondsDateFormatter.string(from: date)),

URLQueryItem(name: "cdt", value: DateFormatter.iso8601DateFormatter.string(from: date)),

//screen resolution
URLQueryItem(name: "res", value:String(format: "%1.0fx%1.0f", screenResolution.width, screenResolution.height)),
Expand Down Expand Up @@ -119,8 +121,29 @@ fileprivate extension DateFormatter {
dateFormatter.dateFormat = "ss"
return dateFormatter
}()
static let iso8601DateFormatter: DateFormatterProtocol = {
if #available(iOS 10, OSX 10.12, watchOS 3.0, tvOS 10.0, *) {
return ISO8601DateFormatter()
} else {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
return formatter
}
}()
}

fileprivate protocol DateFormatterProtocol {
func string(from date: Date) -> String
func date(from string: String) -> Date?
}

@available(iOS 10, OSX 10.12, watchOS 3.0, tvOS 10.0, *)
extension ISO8601DateFormatter: DateFormatterProtocol {}
extension DateFormatter: DateFormatterProtocol {}

fileprivate extension CharacterSet {

/// Returns the character set for characters allowed in a query parameter URL component.
Expand Down