diff --git a/CHANGELOG.md b/CHANGELOG.md index 0047c420..60b71e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +* **improvement** Support new `ca` tracking parameter for tracking requests that aren't page views. [354](https://github.com/matomo-org/matomo-sdk-ios/issues/354) * **improvement** Completely overhauled the UserAgent generation for automatic device and OS discovery. [#353](https://github.com/matomo-org/matomo-sdk-ios/pull/353) ## 7.2.2 diff --git a/MatomoTracker/Event.swift b/MatomoTracker/Event.swift index 2c35997f..57b008ec 100644 --- a/MatomoTracker/Event.swift +++ b/MatomoTracker/Event.swift @@ -18,6 +18,12 @@ public struct Event: Codable { let visitor: Visitor let session: Session + /// This flag defines if this event is a so called cutom action. + /// All events that are not a page view is a custom action. + /// api-key: ca + /// More info: https://github.com/matomo-org/matomo-sdk-ios/issues/354 + let isCustomAction: Bool + /// The Date and Time the event occurred. /// api-key: h, m, s let date: Date @@ -93,7 +99,7 @@ public struct Event: Codable { } extension Event { - public init(tracker: MatomoTracker, action: [String], url: URL? = nil, referer: URL? = nil, eventCategory: String? = nil, eventAction: String? = nil, eventName: String? = nil, eventValue: Float? = nil, customTrackingParameters: [String:String] = [:], searchQuery: String? = nil, searchCategory: String? = nil, searchResultsCount: Int? = nil, dimensions: [CustomDimension] = [], variables: [CustomVariable] = [], contentName: String? = nil, contentInteraction: String? = nil, contentPiece: String? = nil, contentTarget: String? = nil, goalId: Int? = nil, revenue: Float? = nil, orderId: String? = nil, orderItems: [OrderItem] = [], orderRevenue: Float? = nil, orderSubTotal: Float? = nil, orderTax: Float? = nil, orderShippingCost: Float? = nil, orderDiscount: Float? = nil, orderLastDate: Date? = nil) { + public init(tracker: MatomoTracker, action: [String], url: URL? = nil, referer: URL? = nil, eventCategory: String? = nil, eventAction: String? = nil, eventName: String? = nil, eventValue: Float? = nil, customTrackingParameters: [String:String] = [:], searchQuery: String? = nil, searchCategory: String? = nil, searchResultsCount: Int? = nil, dimensions: [CustomDimension] = [], variables: [CustomVariable] = [], contentName: String? = nil, contentInteraction: String? = nil, contentPiece: String? = nil, contentTarget: String? = nil, goalId: Int? = nil, revenue: Float? = nil, orderId: String? = nil, orderItems: [OrderItem] = [], orderRevenue: Float? = nil, orderSubTotal: Float? = nil, orderTax: Float? = nil, orderShippingCost: Float? = nil, orderDiscount: Float? = nil, orderLastDate: Date? = nil, isCustomAction: Bool = true) { self.siteId = tracker.siteId self.uuid = UUID() self.visitor = tracker.visitor @@ -130,5 +136,6 @@ extension Event { self.orderShippingCost = orderShippingCost self.orderDiscount = orderDiscount self.orderLastDate = orderLastDate + self.isCustomAction = isCustomAction } } diff --git a/MatomoTracker/EventAPISerializer.swift b/MatomoTracker/EventAPISerializer.swift index 1b01ad85..2fcf5a56 100644 --- a/MatomoTracker/EventAPISerializer.swift +++ b/MatomoTracker/EventAPISerializer.swift @@ -41,6 +41,7 @@ fileprivate extension Event { let items = [ URLQueryItem(name: "idsite", value: siteId), URLQueryItem(name: "rec", value: "1"), + URLQueryItem(name: "ca", value: isCustomAction ? "1" : nil), // Visitor URLQueryItem(name: "_id", value: visitor.id), URLQueryItem(name: "cid", value: visitor.forcedId), diff --git a/MatomoTracker/MatomoTracker.swift b/MatomoTracker/MatomoTracker.swift index 88ce3d5d..1f718d7e 100644 --- a/MatomoTracker/MatomoTracker.swift +++ b/MatomoTracker/MatomoTracker.swift @@ -295,7 +295,7 @@ extension MatomoTracker { /// - Parameter url: The optional url of the page that was viewed. /// - Parameter dimensions: An optional array of dimensions, that will be set only in the scope of this view. public func track(view: [String], url: URL? = nil, dimensions: [CustomDimension] = []) { - let event = Event(tracker: self, action: view, url: url, dimensions: dimensions) + let event = Event(tracker: self, action: view, url: url, dimensions: dimensions, isCustomAction: false) queue(event: event) } diff --git a/MatomoTrackerTests/Fixtures/MemoryQueueFixtures.swift b/MatomoTrackerTests/Fixtures/MemoryQueueFixtures.swift index 5589ace4..d72b17c4 100644 --- a/MatomoTrackerTests/Fixtures/MemoryQueueFixtures.swift +++ b/MatomoTrackerTests/Fixtures/MemoryQueueFixtures.swift @@ -4,33 +4,44 @@ struct EventFixture { static func event() -> Event { let visitor = Visitor(id: "spec_visitor_id", forcedId: nil, userId: "spec_user_id") let session = Session(sessionsCount: 0, lastVisit: Date(), firstVisit: Date()) - return Event(uuid: UUID(), siteId: "spec_1", visitor: visitor, session: session, date: Date(), url: URL(string: "http://spec_url")!, actionName: ["spec_action"], language: "spec_language", isNewSession: true, referer: nil, - customVariables: [], - eventCategory: nil, - eventAction: nil, - eventName: nil, - eventValue: nil, - campaignName: nil, - campaignKeyword: nil, - searchQuery: nil, - searchCategory: nil, - searchResultsCount: nil, - dimensions: [], - customTrackingParameters: [:], - contentName: nil, - contentPiece: nil, - contentTarget: nil, - contentInteraction: nil, - goalId: nil, - revenue: nil, - orderId: nil, - orderItems: [], - orderRevenue: nil, - orderSubTotal: nil, - orderTax: nil, - orderShippingCost: nil, - orderDiscount: nil, - orderLastDate: nil) + return Event( + uuid: UUID(), + siteId: "spec_1", + visitor: visitor, + session: session, + isCustomAction: true, + date: Date(), + url: URL(string: "http://spec_url")!, + actionName: ["spec_action"], + language: "spec_language", + isNewSession: true, + referer: nil, + customVariables: [], + eventCategory: nil, + eventAction: nil, + eventName: nil, + eventValue: nil, + campaignName: nil, + campaignKeyword: nil, + searchQuery: nil, + searchCategory: nil, + searchResultsCount: nil, + dimensions: [], + customTrackingParameters: [:], + contentName: nil, + contentPiece: nil, + contentTarget: nil, + contentInteraction: nil, + goalId: nil, + revenue: nil, + orderId: nil, + orderItems: [], + orderRevenue: nil, + orderSubTotal: nil, + orderTax: nil, + orderShippingCost: nil, + orderDiscount: nil, + orderLastDate: nil) } }