Enable a Test Drive

This section describes how to create a basic test drive experience offered by the IQL program, and includes the following topics:

Enable a Test Drive

Enable a Test Drive

Enable a Test Drive

Enable a Test Drive

1.0. Integrate Driver Status API

Perform the following tasks to fetch and integrate the driverStatus API with your application:

1.1. Create a Wrapper for driverStatus API

Create a wrapper for the driverStatus Endpoint in your application backend. Refer to the sample implementation provided in the following resource:

1.2. Fetch the Latest Status Using the driverStatusAPI

  1. Create a data model class named IQLDriverStatus to parse the data from the driverStatus API.

  2. Run the FetchIQLDriverStatusJobFetch method to obtain driver status when the user logs in and every time the application launches and cache the response locally. Refer to the driverStatus EndpointAPI endpoint for more information.

class FetchIQLDriverStatusJob: Job {
    func run() {
        DDLogDebug("Start: Fetch driver status")
        let core = IQLRef.sharedInstance
        guard let driverId = core.loginRepository.currentUser?.driverId else {
            fatalError("User id doesn't exist")
        }
        core.api.getDriverStatus(driverId: driverId,
                                 onSuccess: { driverStatus in
            core.iqlDriverStatusRepository.refreshDriverStatus(driverStatus: driverStatus)
        }, onFailure: { failure in
            DDLogDebug("Failure - \(failure)")
            DDLogDebug("End: Update driver status Failed")
        }) { error in
            DDLogDebug("Error - \(error)")
            DDLogDebug("End: Update driver status Error")
        }
    }
}
class API {
    ...
    ...
    func getDriverStatus(driverId: String,
                         onSuccess: ((_ driverStatus: IQLDriverStatus) -> Void)?,
                         onFailure: ((_ failureResponse: FailureResponse) -> Void)?,
                         onError: ((_ error: APIError) -> Void)? ) {
        executeGetRequest(
            endpoint: .getDriverStatus,
            pathParams: ["driver_id": driverId],
            onSuccess: onSuccess, onFailure: onFailure, onError: onError)
    }
    ...
    ...
}

class IQLDriverStatusRepository {
    ...
    ...
    func refreshDriverStatus(driverStatus: IQLDriverStatus) {
        let apiCallTimeDate = Date()
        UserDefaults.standard.set(apiCallTimeDate, forKey: self.postDateKey)
        iqlDriverStatusDao.deleteAll()
        iqlDriverStatusDao.insert(record: driverStatus)
        if (driverStatus.metrics?.offerAvailable ?? false) {
            loginRepo?.state = .Qualified
            UserDefaults.standard.set(true, forKey: "isQualified")
            IQLRef.sharedInstance.jobManager.enqueue(job: FetchADUnitJob())
        }
    }
    ...
    ...
}
struct IQLDriverStatus: Codable {
    var driverId: String?
    var startDate: String?
    var endDate: String?
    var metrics: Metrics?

    enum CodingKeys: String, CodingKey {
        case driverId = "driver_id"
        case startDate = "start_date"
        case endDate = "end_date"
        case metrics = "metrics"
    }

    struct Metrics: Codable {
        var dateFirstDrive: String
        var uniqueDrivingDays: Int32 = 0
        var eventRating: EventRating
        var tripsCount: Double = 0
        var distanceInMiles: Double = 0
        var distanceInKm: Double = 0
        var zendriveScore: Double = 0
        var progressPercent: Int32 = 0
        var offerAvailable: Bool?
        var offerClicked: Bool?


        enum CodingKeys: String, CodingKey {
            case dateFirstDrive = "date_first_drive"
            case tripsCount = "trips_count"
            case distanceInMiles = "distance_miles"
            case distanceInKm = "distance_kms"
            case zendriveScore = "zendrive_score"
            case eventRating = "event_rating"
            case uniqueDrivingDays = "unique_driving_days"
            case progressPercent = "progress_percentage"
            case offerAvailable = "offer_available"
            case offerClicked = "offer_clicked"
        }

        struct EventRating: Codable {
            var rapidAcceleration: Int
            var phoneUse: Int
            var hardBrake: Int
            var hardTurn: Int
            var overSpeeding: Int
            enum CodingKeys: String, CodingKey {
                case rapidAcceleration = "rapid_acceleration"
                case phoneUse = "phone_use"
                case hardBrake = "hard_brake"
                case hardTurn = "hard_turn"
                case overSpeeding = "overspeeding"
            }
        }
    }
}

2.0. Build a Driver Performance Experience

Use the UX designs and code provided in the reference implementation link to build a driver performance experience for your users.

3.0. IQL Reference Application UX Design

Here is the overall design implementation for the IQL Reference Application:

4.0. Publisher Integration Testing Checklist

Follow the below-given checklist to test the Enable a Test Drive process:

  • Trip: After the user onboarding is complete, ensure that Zendrive SDK is working as expected allowing the user to take a few trips. All trips taken by the user should be recorded.

  • Zendrive Dashboard: Ensure that any program related data, for example, progress %, driving days, miles driven, trips taken and so on, are presented accurately within the application.

  • Refresh: Ensure that any data displayed in the application is updated whenever the program screen is loaded. This ensures that the latest data is presented to the users at all times. This information should match the values coming from driverStatus API.