Implementation Steps
The SDK must be initialised in your AppDelegate
To implement the SDK’s Standalone flow within your app, please use the following steps:
Steps
Optional Extras
Initialise the SDK in your App Delegate
import CarTrawlerSDK
// In application(_:didFinishLaunchingWithOptions:)
CarTrawlerSDK.sharedInstance().initialiseSDK(with: nil,
customParameters: nil,
production: false)
The production parameter must be set to true when submitting your app to the AppStore.
style: An optional CTStyle object, used to set the fonts as well as the primary, secondary, and accent colors in the SDK. Please ensure any custom fonts used are included in your main bundle.
customParameters: An optional dictionary of parameters, custom to a particular partner. Pass nil unless CarTrawler has given you values to use.
For a full list of property descriptions, please click here
Initialise the CTContext object with the required parameters
This can be done in the view controller the SDK will be presented from.
The implementationID is needed by the SDK to fetch partner specific configuration.
import CarTrawlerSDK
let context = CTContext(implementationID: "your implementation ID",
clientID: "your client ID",
flow: .standAlone)
context.countryCode = "IE" // The country code associated with the device’s system region is used by default.
context.currencyCode = "EUR" // The currency associated with the device’s system region is used by default.
context.languageCode = "EN" // The language associated with the device’s system region is used by default.
The above properties are required, and the countryCode property refers to the country of residency. This is used to make search requests.
Object Description
class CTContext: NSObject {
let implementationID: String
let clientID: String
let flowType: CTFlowType
let countryCode: String
let currencyCode: String
let languageCode: String
let pickupDate: Date
let dropOffDate: Date
let pickupLocation: String
let dropOffLocation: String
let pickupLocationID: String
let dropOffLocationID: String
let pinnedVehicleID: String
let passenger: CTPassenger
let loyaltyToken: String
let orderID: String
let flightDetails: CTFlightDetails
let utmParameters: CTUTMParameters
let pickupLocationCoordinate: CLLocationCoordinate2D
let dropOffLocationCoordinate: CLLocationCoordinate2D
}
Click here for an in depth explanation of CTContext’s properties.
Present the SDK via Modal or Push Presentation
The SDK presents the CarTrawler web booking flow configured for your implementationID. The search, vehicle list, extras, insurance, payment and confirmation steps are all rendered by the web booking flow.
In the view controller you wish to present the SDK from, add the following code after configuring your CTContext:
let viewController = UIViewController()
CarTrawlerSDK.sharedInstance().present(from: viewController, context: context)
Alternatively, in the navigation controller you wish to push the SDK from, add the following code after configuring your CTContext:
let navigationController = UINavigationController()
CarTrawlerSDK.sharedInstance().push(fromNavigationViewController: navigationController, context: context)
Start the Standalone flow on the search results
When launching the Standalone flow, it is possible to open the web booking flow directly on the search results by setting the search properties of your CTContext object.
This is entirely optional.
For this alternate starting point in the flow, pick-up and drop-off dates and a pick-up location (IATA code, location ID or coordinates) must be provided.
// Create a context for the Standalone flow
let context = CTContext(implementationID: "your implementation ID",
clientID: "your client ID",
flow: .standAlone)
// Set required properties
context.countryCode = "IE" // The country code associated with the device’s system region is used by default.
context.currencyCode = "EUR" // The currency associated with the device’s system region is used by default.
context.languageCode = "EN" // The language associated with the device’s system region is used by default.
// Set pick-up and drop-off locations using location or IATA codes
// Pick-up at Dublin Airport
context.pickupLocationID = "11" // or context.pickupLocation = "DUB"
// Drop-off at Cork Airport
context.dropOffLocationID = "1316" // or context.dropOffLocation = "ORK"
// Sample dates
var dateComponent = DateComponents()
dateComponent.month = 1
let nextMonth = Calendar.current.date(byAdding: dateComponent, to: Date())
dateComponent.day = 3
let nextMonthPlusThreeDays = Calendar.current.date(byAdding: dateComponent, to: Date())
// Set pick-up and drop-off dates
context.pickupDate = nextMonth! // next month sample date
context.dropOffDate = nextMonthPlusThreeDays! // next month + 3 days sample date
// Set your viewController as the CarTrawlerSDK delegate
context.delegate = self
A vehicle can be highlighted in the results by setting pinnedVehicleID (adding a vehicle reference ID). To get a reference ID, you can use our Vehicles API.
context.pinnedVehicleID = "1892038" // Vehicle RefID
Click here for an in depth explanation of the relevant CTContext properties
Start the Standalone Flow via URL Deeplink
It is possible to launch the Standalone flow using a URL, which may come from a push notification or native app deep link for example. This is entirely optional.
The URL should have the following pattern:
schema://host?param1=123¶m2=abcd¶mN=xyz
This example will open the web booking flow on the search results:
schema://ct-car-rental?type=search-result&client_id=123456&pt=2023-09-08T09:44:35+0100&dt=2023-09-10T10:44:35+0100&pkIATA=DUB
A client ID (client_id) must be provided as part of your URL in order for the SDK to function properly.
Similar to the methods listed previously for launching the Standalone flow, the URL is used by CTContext. A separate initialiser exists for this purpose:
let url = "airline://ct-car-rental?type=search-result&client_id=123456&pt=2023-09-08T09:44:35+0100&dt=2023-09-10T10:44:35+0100&pkIATA=DUB"
let context = CTContext(implementationID: "your implementation ID", appDeeplinkURL: url)
You can then present the SDK:
CarTrawlerSDK.sharedInstance().present(from: self, context: context)
See here for more details
Start Standalone flow on the web search page
To open the web booking flow on its search page, simply set the type to landing: type=landing
Start Standalone flow on the search results
To open the web booking flow on the search results, set the type to search-result: type=search-result
Make sure to provide pickup and drop off dates, and a pickup location ID, IATA code or coordinates. If any of these are missing, the SDK will instead open the web search page.
Import a booking
Set the type to booking-details: type=booking-details and provide the booking id and the email used for the booking. Both are required. The booking is imported into the SDK’s local storage and the web booking flow is presented.
List of Parameters
Below are all the available parameters for use in the URL.
Landing
| Parameter | Example | Required |
|---|---|---|
| type | landing | yes |
| client_id | 123456 | yes |
| ctyCode (residency) | IE | no |
| ccy (currency) | EUR | no |
Import a booking
| Parameter | Example | Required |
|---|---|---|
| type | booking-details | yes |
| client_id | 123456 | yes |
| ctyCode (residency) | IE | no |
| ccy (currency) | EUR | no |
| booking | IE123456789 | yes |
| mail@mail.com | yes |
Search Results
| Parameter | Example | Required |
|---|---|---|
| type | search-result | yes |
| client_id | 123456 | yes |
| pt (pickup time) | 2023-08-18T10:00:00Z | yes |
| dt (drop off time) | 2023-08-20T10:00:00Z | yes |
| pkIATA (pickup IATA) | DUB | yes (for IATA search) |
| doIATA (drop off IATA) | DUB | no |
| pl (pickup location ID) | 11 | yes (for ID search) |
| dl (drop off location ID) | 11 | no |
| pkLtLng (pickup coordinates) | 53.3333,-6.24089 | yes (for geo search) |
| doLtLng (drop off coordinates) | 53.3333,-6.24089 | no |
| age | 30 | no |
| ctyCode (residency) | IE | no |
| ccy (currency) | EUR | no |
| pinVeh (pinned vehicle) | 123456789 | no |
Adding Flight Information
Partners can optionally add flight data when initialising the SDK. The following CTFlightDetails values are forwarded to the web booking flow:
| Parameter | Description | Example | Type |
|---|---|---|---|
| pnr | Flight PNR. Also used as the order ID when orderID is not set | CT123456 | String |
| visitorID | Used to track visitor abandonment | abc123-visitor-id | String |
| flightFareSize | Flight fare T-shirt sizing; typical values include S, M, L, and XL | M | String |
| context | Where in the flow the SDK is loaded. When set to MMB, the search is built from flightOrigin and flightReturn | MMB | String |
| flightOrigin | Origin flight details separated by pipes: IATA departure, IATA arrival, datetime departure, datetime arrival, flight number. Used when context is MMB | DUB|LHR|2025-01-16T06:05:00|2025-01-16T07:25:00|XX8719 | String |
| flightReturn | Return flight details, same format as flightOrigin. Used when context is MMB | LHR|DUB|2025-01-22T21:20:00|2025-01-23T22:45:00|XX8720 | String |
//Example CTFLightDetails initialisation
let flightDetails = CTFlightDetails()
flightDetails.pnr = "TEYI89"
flightDetails.visitorID = "abc123-visitor-id"
flightDetails.flightFareSize = "M"
//Use CTFLightDetails as part of the context
let context = CTContext(implementationID: "your implementation ID",
clientID: "your client ID",
flow: .standAlone)
context.flightDetails = flightDetails
For the full list of flight values used by the Grid View, see In Path Grid View property descriptions.
Adding UTM tracking data
For enhanced reporting partners can optionally add tracking data in the form of UTM parameters, which are sent with the SDK analytics events. The meaning and usage of these parameters are as standard.
A new CTUTMParameters object is added with the following parameters.
//Example CTUTMParameters initialisation
let utmParameters = CTUTMParameters()
utmParameters.source = "partner_utm_source"
utmParameters.medium = "partner_utm_medium"
utmParameters.campaign = "partner_utm_campaign"
utmParameters.term = "partner_utm_term"
utmParameters.content = "partner_utm_content"
context.utmParameters = utmParameters
Prepopulate driver age and residency
The driver age and country of residence used for the search can be set by creating a CTPassenger object and setting the passenger property on your CTContext.
//Passenger object
let passenger = CTPassenger(firstName: "Ryan",
lastName: "O'Connor",
addressLine1: "DunDrum",
addressLine2: "Dublin 14",
city: "Dublin",
postcode: "Dublin 14",
countryCode: "IE",
age: 25,
email: "john.doe@example.com",
phone: "0838880000",
phoneCountryPrefix: "353",
loyaltyProgramNumber: "1234")
context.passenger = passenger
Only age and countryCode are forwarded to the web booking flow. CTPassenger countryCode takes priority over CTContext’s countryCode property when we make search requests.