Skip to content

Commit

Permalink
Adds cdt parameter to tracking query items (#301)
Browse files Browse the repository at this point in the history
* Adds `cdt` parameter to tracking query items

* Using ISO8601 for cdt parameter (via ISO8601DateFormatter if available)

* Bump changelog
  • Loading branch information
notjosh authored and brototyp committed Sep 3, 2019
1 parent ccc4519 commit b856ddc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit b856ddc

Please sign in to comment.