-
Notifications
You must be signed in to change notification settings - Fork 0
Datalayer
The purpose behind implementing a datalayer for the Integrated Platform is to provide a simple, fairly standard method for sharing data between the host (dealer) website, and the application itself. This will enable Ava to use more contextually relevant information in the various API calls between the client and the server.
Before getting into the setup, there are just a couple of things to keep in mind when using the datalayer:
- In the examples outlined below, you will see that the full path to the datalayer is referenced each time it is used. This is because the reference to the array may change after the api initializes. i.e. if you save a reference to the push() method before the api loads, then you will be pushing to the wrong object after the load finishes, and the app won't see your data.
A collection of install/usage patterns can be found here
The datalayer is an "always-on" feature, so it will be available to you as soon as the api has hydrated. In order to use it, you will need to either:
a. pre-initialize the api object, or;
b. wait for the api to finish loading
The most effective/reliable method would be pre-initializing the api object, as outlined below. Additional methods will also be included in the advanced usage section.
-
Before you can use the datalayer, there needs to be an array to push into. When pre-initializing the api object, you are creating your own array, and the core api layer will reuse that object.
<script type="application/javascript"> window.askAva = (window.askAva || { datalayer: [] }); </script>
-
After the api object is initialized, either by the api core or by your own action, you can push data into the datalayer, which will, in effect, expose it for use in the widget. See Known Structures below to see what fields are available, as well as their types.
<script> window.askAva.datalayer.push("asset", { status: 'Used', year: '2020', make: 'Ford', model: 'Fusion', trim: 'SE', exteriorColor : 'Red', vin : '3FA6P0HD1LR182816', msrp : '31999', displayedPrice : '31999', engine : '1.5L 4cyl', transmission : 'Automatic', interiorColor : 'Othr', stockNumber : 'N104982A', imageUrl: 'https://images.edealer.ca/13/56926/106810919.jpeg' }) </script>
The datalayer has methods which provide access to some basic CRUD functionality:
-
push(type: StructType | string, data: Struct, query?: QueryDef)
#The
push()
method appends an object to the datalayer (or otherwise mutates, depending on the circumstance), as well as capturing metadata about the data that allows it to be queried later on-
The
type
parameter indicates to the application what the data pertains to. There are various "well-known" types that the app is aware of, which is how it can know what data to use in which circumstance. See Known Structures below for a breakdown of the currenttype
structures- Any arbitrary
type
parameter may be specified, but using any other than the "well-known" types will not be very effective, because the app will not know what to do with them.
- Any arbitrary
-
The
data
parameter is an object matching the structure of the definedtype
. These object structures are defined below inKnown Structures
.- If the
type
parameter is not a "well-known" type, then the data structure may be any arbitrary object structure.
- If the
-
WIP: The
query
parameter allows you to define some metadata that will be used to match against preexisting records. If the criteria matches an existing record, that record will be replaced with the new one.- NOT YET IMPLEMENTED
-
-
WIP:
get(type: StructType, query?: QueryDef)
#NOT YET IMPLEMENTED The
get()
method should be used as the way to retrieve pre-existing records from the datalayer.- The
type
parameter is the same as defined above for the push method - The
query
parameter defines additional constraints to match against when retrieving a record.
- The
- Asset Information
-
StructType
type parameter:asset
type AssetInfo = {
status: string; // Used
year: string; // 2020
make: string; // Ford
model: string; // Fusion
trim: string; // SE
exteriorColor: string; // Red
vin: string; // 3FA6P0HD1LR182816
msrp: string; // 31999
displayedPrice: string; // 31999
engine: string; // 1.5L 4cyl
transmission: string; // Automatic
interiorColor: string; // Othr
stockNumber: string; // N104982A
}
NOT YET IMPLEMENTED
- Waiting for api hydration TBD
- Integrated Platform