Skip to content

Commit 846a6ec

Browse files
committed
Update insertGalleryContent documentation.
1 parent 2ac59ae commit 846a6ec

File tree

1 file changed

+70
-24
lines changed

1 file changed

+70
-24
lines changed

source/includes/_methods.md

Lines changed: 70 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,41 +159,87 @@ Field Name | Purpose | Field Format
159159
`intent` | The intention of the CTA you are inserting. | String
160160
`setupFunction(meta)` | The payload object for the current vehicle. | Object
161161

162-
## API.insertGalleryContent(target, objOrArray)
162+
## API.insertGalleryContent(target, arrayOfObjects)
163163

164164
> Usage
165165
166166
```javascript
167167
(async APILoader => {
168168
const API = await APILoader.create(document.currentScript);
169-
API.insertGalleryContent('vehicle-media', [
170-
{
171-
type: 'image',
172-
position: 'primary',
173-
src: 'https://yourdomain.com/primary.jpg',
174-
thumbnail: 'https://yourdomain.com/primary-thumb.jpg'
175-
},
176-
{
177-
type: 'image',
178-
position: 'secondary',
179-
src: 'https://yourdomain.com/secondary.jpg',
180-
thumbnail: 'https://yourdomain.com/secondary-thumb.jpg'
181-
},
182-
{
183-
type: 'image',
184-
position: 'last',
185-
src: 'https://yourdomain.com/last.jpg',
186-
thumbnail: 'https://yourdomain.com/last-thumb.jpg'
187-
}
188-
]);
169+
170+
// This informs your script when the displayed list of vehicles has changed, or when a Vehicle Details Page has loaded.
171+
API.subscribe('vehicle-data-updated-v1', ev => {
172+
173+
// This obtains a list of VINs for the displayed vehicles.
174+
const vins = await API.utils.getAttributeForVehicles('vin');
175+
176+
// With the list of VINs, you could query your service
177+
// to obtain the dataset of imagery for those vehicles.
178+
179+
// Code to query your service goes here.
180+
const imagesData = await queryYourService(vins);
181+
182+
// With the returned `imagesData`, you could then construct an array of objects in the following format to use when calling `API.insertGalleryContent`.
183+
const imagesToInsert = [
184+
{
185+
vin: '1HGCV1F46LA144134',
186+
images: [
187+
{
188+
type: 'image',
189+
position: 'primary',
190+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Primary Image',
191+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Primary Image',
192+
},
193+
{
194+
type: 'image',
195+
position: 'secondary',
196+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Secondary Image',
197+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Secondary Image',
198+
},
199+
{
200+
type: 'image',
201+
position: 'last',
202+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Last Image',
203+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 1 Last Image',
204+
}
205+
]
206+
},
207+
{
208+
vin: '1HGCV1F48LA139453',
209+
images: [
210+
{
211+
type: 'image',
212+
position: 'primary',
213+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Primary Image',
214+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Primary Image',
215+
},
216+
{
217+
type: 'image',
218+
position: 'secondary',
219+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Secondary Image',
220+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Secondary Image',
221+
},
222+
{
223+
type: 'image',
224+
position: 'last',
225+
src: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Last Image',
226+
thumbnail: 'https://via.placeholder.com/530x360.png?text=Vehicle 2 Last Image',
227+
}
228+
]
229+
}
230+
];
231+
232+
// And finally, call insertGalleryContent with the new imagery data.
233+
API.insertGalleryContent('vehicle-media', imagesToInsert);
234+
});
189235
})(window.DDC.APILoader);
190236
```
191237

192-
The `insertGalleryContent` method allows you to add media to media galleries across various pages of Dealer.com sites. The only currently supported target is `vehicle-media`, which will insert media into the media carousel of Vehicle Details Pages.
238+
The `insertGalleryContent` method allows you to add media to media galleries across various pages of Dealer.com sites. The only currently supported target is `vehicle-media`, which will insert media into the media carousels on Search Results Pages and Vehicle Details Pages.
193239

194-
`objOrArray` is an array of objects describing the media to be inserted. If you have a single image, you can pass a single object instead. Each object has a `type` field to specify the type of media to be inserted. The only currently supported media type is `image`.
240+
`arrayOfObjects` is an array of objects describing the media to be inserted. Each object requires a `vin` field for the target vehicle, as well as an `images` array with fields describing the images to insert for that vehicle. The `type` field specifies the type of media to be inserted. The only currently supported media type is `image`. Utilizing `vehicle-data-updated-v1` to know when the list of vehicles changes combined with `API.utils.getAttributeForVehicles`, you can easily obtain a list of the VINs for vehicles shown on the page. With this data, you could query your service to get the dataset of imagery for those vehicles, then construct the array of objects for `API.insertGalleryContent`. See the example code for more details on this approach.
195241

196-
The `image` type supports the following additional attributes:
242+
The `images` array objects support the following additional attributes:
197243

198244
Name | Description
199245
-------------- | --------------

0 commit comments

Comments
 (0)