5 // Created by Cornelius Horstmann on 21.12.16.
6 // Copyright © 2016 PIWIK. All rights reserved.
12 /// Represents an event of any kind.
14 /// - Note: Should we store the resolution in the Event (cleaner) or add it before transmission (smaller)?
16 /// - Add Campaign Parameters: _rcn, _rck
18 /// - Event Tracking info
19 /// - Add Content Tracking info
20 /// - Add Ecommerce info
23 /// Most properties represent a key defined at: [Tracking HTTP API](https://developer.piwik.org/api-reference/tracking-api). Keys that are not supported for now are:
25 /// - idsite, rec, rand, apiv, res, cookie,
26 /// - All Plugins: fla, java, dir, qt, realp, pdf, wma, gears, ag
27 /// - cid: We will use the uid instead of the cid.
34 /// The Date and Time the event occurred.
38 /// The full URL for the current action.
42 /// api-key: action_name
43 let actionName: [String]
45 /// The language of the device.
46 /// Should be in the format of the Accept-Language HTTP header field.
50 /// Should be set to true for the first event of a session.
51 /// api-key: new_visit
52 let isNewSession: Bool
54 /// Currently only used for Campaigns
57 let screenResolution : CGSize = Device.makeCurrentDevice().screenSize
60 let customVariables: [CustomVariable]
63 /// https://piwik.org/docs/event-tracking/
64 let eventCategory: String?
65 let eventAction: String?
66 let eventName: String?
67 let eventValue: Float?
70 /// https://matomo.org/docs/tracking-campaigns/
71 let campaignName: String?
72 let campaignKeyword: String?
75 /// api-keys: search, search_cat, search_count
76 let searchQuery: String?
77 let searchCategory: String?
78 let searchResultsCount: Int?
80 let dimensions: [CustomDimension]
82 let customTrackingParameters: [String:String]
85 /// https://matomo.org/docs/content-tracking/
86 let contentName: String?
87 let contentPiece: String?
88 let contentTarget: String?
89 let contentInteraction: String?
93 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) {
94 self.siteId = tracker.siteId
96 self.visitor = tracker.visitor
97 self.session = tracker.session
99 self.url = url ?? tracker.contentBase?.appendingPathComponent(action.joined(separator: "/"))
100 self.actionName = action
101 self.language = Locale.httpAcceptLanguage
102 self.isNewSession = tracker.nextEventStartsANewSession
103 self.referer = referer
104 self.eventCategory = eventCategory
105 self.eventAction = eventAction
106 self.eventName = eventName
107 self.eventValue = eventValue
108 self.searchQuery = searchQuery
109 self.searchCategory = searchCategory
110 self.searchResultsCount = searchResultsCount
111 self.dimensions = tracker.dimensions + dimensions
112 self.campaignName = tracker.campaignName
113 self.campaignKeyword = tracker.campaignKeyword
114 self.customTrackingParameters = customTrackingParameters
115 self.customVariables = tracker.customVariables + variables
116 self.contentName = contentName
117 self.contentPiece = contentPiece
118 self.contentTarget = contentTarget
119 self.contentInteraction = contentInteraction