-
Notifications
You must be signed in to change notification settings - Fork 1
Google Analytics
Andrew Wagner edited this page Jul 23, 2019
·
1 revision
Communicate with the API for Google Analytics.
You will have to set the tracking Id on the service before you can use it.
The easiest way to do that is to set it on the shared instance.
Google.Analytics.shared.trackingId = "UA-999999999-9"Collect data, for example: record a page view.
There are many optional things to input. At a minimum, you only need an endpoint.
let record = Google.Analytics.Record(kind: .pageView(endpoint: "/test"))
Google.Analytics.Collect().makeRequest(with: record) { _ in }That records a page view at "/test".
However, there are a number of optional parameters for a record:
let record = Google.Analytics.Record(
kind: .pageView(endpoint: "/test"),
// Override the tracking id on the service
trackingId: "UA-222222222-2",
// The IP address of the client
ipAddress: "0.0.0.0",
// A unique identifier for the client
clientId: "CLIENT1",
// Custom fields
customField1: "Field1",
customField2: "Field2",
customField3: "Field3"
)