Skip to content

Commit 277a866

Browse files
committed
Consistent test-integration init of new WIAPI for easier testing of code. Improve documentation for getUrlParams function.
1 parent 6b234c9 commit 277a866

File tree

7 files changed

+52
-38
lines changed

7 files changed

+52
-38
lines changed

source/includes/_debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
```javascript
66
(function(WIAPI) {
7-
var API = new WIAPI();
7+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
88
API.subscribe('page-load-v1', function (ev) {
99
if (ev.payload.searchPage) {
1010
API.log('My integration has loaded and this is a search results page.');

source/includes/_events.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ To receive data for events, you must opt-in to event subscriptions. Each event i
177177
178178
```javascript
179179
(function(WIAPI) {
180-
var API = new WIAPI();
180+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
181181
API.subscribe('page-load-v1', function(ev) {
182182
API.log(ev);
183183
});
@@ -200,7 +200,7 @@ The page load event is useful to determine the context of the current page. By m
200200
201201
```javascript
202202
(function(WIAPI) {
203-
var API = new WIAPI();
203+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
204204
API.subscribe('dealership-info-v1', function(ev) {
205205
API.log(ev);
206206
});
@@ -223,7 +223,7 @@ The dealership info event is useful if you need to know the name and address of
223223
224224
```javascript
225225
(function(WIAPI) {
226-
var API = new WIAPI();
226+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
227227
API.subscribe('vehicle-shown-v1', function(ev) {
228228
API.log(ev);
229229
});
@@ -247,7 +247,7 @@ On a vehicle deals page, a single event is fired because you are viewing a singl
247247
248248
```javascript
249249
(function(WIAPI) {
250-
var API = new WIAPI();
250+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
251251
API.subscribe('vehicle-data-updated-v1', function(data) {
252252
API.log(data.payload.pageData); // Outputs the Page Data object to the console.
253253
API.log(data.payload.vehicleData); // Outputs the updated Vehicle Data object to the console.

source/includes/_locations.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See the <a href="#ddc-api-insert-key-name-callback-elem-meta">insert documentati
1010
1111
```javascript
1212
(function(WIAPI) {
13-
var API = new WIAPI();
13+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
1414
API.insert('vehicle-media', function(elem, meta) {
1515
// This element is positioned below the vehicle image area on vehicle search pages.
1616
});
@@ -21,7 +21,7 @@ See the <a href="#ddc-api-insert-key-name-callback-elem-meta">insert documentati
2121
2222
```javascript
2323
(function(WIAPI) {
24-
var API = new WIAPI();
24+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
2525
API.subscribe('page-load-v1', function(ev) {
2626
if (ev.payload.searchPage) {
2727
API.insert('vehicle-media', function(elem, meta) {
@@ -49,7 +49,7 @@ This element is positioned below the vehicle image area on vehicle search pages.
4949
5050
```javascript
5151
(function(WIAPI) {
52-
var API = new WIAPI();
52+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
5353
API.insert('vehicle-badge', function(elem, meta) {
5454
// This element is positioned below the vehicle tech specs area on vehicle search and detail pages.
5555
});
@@ -60,7 +60,7 @@ This element is positioned below the vehicle image area on vehicle search pages.
6060
6161
```javascript
6262
(function(WIAPI) {
63-
var API = new WIAPI();
63+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
6464
API.subscribe('page-load-v1', function(ev) {
6565
if (ev.payload.searchPage || ev.payload.detailPage) {
6666
API.insert('vehicle-badge', function(elem, meta) {
@@ -94,7 +94,7 @@ This element is positioned below the vehicle tech specs area on vehicle search a
9494
9595
```javascript
9696
(function(WIAPI) {
97-
var API = new WIAPI();
97+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
9898
API.insert('vehicle-pricing', function(elem, meta) {
9999
// This element is positioned below the vehicle pricing area on vehicle search and detail pages.
100100
});
@@ -105,7 +105,7 @@ This element is positioned below the vehicle tech specs area on vehicle search a
105105
106106
```javascript
107107
(function(WIAPI) {
108-
var API = new WIAPI();
108+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
109109
API.subscribe('page-load-v1', function(ev) {
110110
// Only execute the code on search results and vehicle details pages.
111111
if (ev.payload.searchPage || ev.payload.detailPage) {
@@ -133,7 +133,7 @@ This element is positioned below the vehicle pricing area on vehicle search and
133133
134134
```javascript
135135
(function(WIAPI) {
136-
var API = new WIAPI();
136+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
137137
API.insert('vehicle-media-container', function(elem, meta) {
138138
// This element is the media gallery container on vehicle deals pages.
139139
// Injecting into this location will replace the media gallery with the elements you insert.
@@ -145,7 +145,7 @@ This element is positioned below the vehicle pricing area on vehicle search and
145145
146146
```javascript
147147
(function(WIAPI) {
148-
var API = new WIAPI();
148+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
149149
API.subscribe('page-load-v1', function(ev) {
150150
if (ev.payload.detailPage) {
151151
API.insert('vehicle-media-container', function(elem, meta) {
@@ -167,7 +167,7 @@ This element is the media gallery container on vehicle deals pages. Injecting in
167167
168168
```javascript
169169
(function(WIAPI) {
170-
var API = new WIAPI();
170+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
171171
API.insert('primary-banner', function(elem, meta) {
172172
// This element is typically positioned in a prominent location above the vehicle listings on the Search Results Page.
173173
// On the Details page, it is near the top of the vehicle information, below the media gallery.
@@ -179,7 +179,7 @@ This element is the media gallery container on vehicle deals pages. Injecting in
179179
180180
```javascript
181181
(function(WIAPI) {
182-
var API = new WIAPI();
182+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
183183
API.subscribe('page-load-v1', function(ev) {
184184
if (ev.payload.searchPage || ev.payload.detailPage) {
185185
API.insert('primary-banner', function(elem, meta) {

source/includes/_methods.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
```javascript
88
(function(WIAPI) {
9-
var API = new WIAPI();
9+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
1010
API.subscribe('event-name-and-version', function(event) {
1111
API.log(event);
1212
});
@@ -162,7 +162,7 @@ Field Name | Purpose | Field Format
162162
163163
```javascript
164164
(function(WIAPI) {
165-
var API = new WIAPI();
165+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
166166
API.insert('location-name', function(elem, meta) {
167167
API.log(elem); // The DOM element where markup may be inserted.
168168
API.log(meta); // The payload object for the current insertion point.
@@ -182,7 +182,7 @@ This acts as an event subscription, so as the application displays new vehicles
182182
183183
```javascript
184184
(function(WIAPI) {
185-
var API = new WIAPI();
185+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
186186
API.insertOnce('location-name', function(elem, meta) {
187187
API.log(elem); // The DOM element where markup may be inserted.
188188
API.log(meta); // The payload object for the current insertion point.
@@ -247,7 +247,7 @@ Field Name | Purpose | Field Format
247247
248248
```javascript
249249
(function(WIAPI) {
250-
var API = new WIAPI();
250+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
251251
var button = API.create('button', {
252252
text: 'Visit Google',
253253
src: 'https://www.google.com/',
@@ -272,7 +272,7 @@ Currently only the "button" type is supported, however other types will soon be
272272
273273
```javascript
274274
(function(WIAPI) {
275-
var API = new WIAPI();
275+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
276276
API.append(targetEl, appendEl);
277277
})(window.DDC.API);
278278
```
@@ -281,7 +281,7 @@ Currently only the "button" type is supported, however other types will soon be
281281
282282
```javascript
283283
(function(WIAPI) {
284-
var API = new WIAPI();
284+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
285285
API.insert('target-location-name', function(elem, meta) {
286286
var lowPrice = Math.round(meta.finalPrice - 1000);
287287
var highPrice = Math.round(meta.finalPrice + 1000);
@@ -307,7 +307,7 @@ When calling the insert method, the goal is to insert some markup into a locatio
307307
308308
```javascript
309309
(function(WIAPI) {
310-
var API = new WIAPI();
310+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
311311
// Loads a JavaScript file
312312
API.loadJS('https://www.company.com/script.js')
313313
.then(function() {
@@ -324,7 +324,7 @@ The loadJS method is a simple way to include additional JavaScript files require
324324
325325
```javascript
326326
(function(WIAPI) {
327-
var API = new WIAPI();
327+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
328328
// Loads a CSS stylesheet
329329
API.loadCSS('https://www.company.com/integration.css')
330330
.then(function() {

source/includes/_requirements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Your code should be minimal and perform only actions necessary to bootstrap your
4141
4242
```javascript
4343
(function(WIAPI) {
44-
var API = new WIAPI();
44+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
4545
// API.subscribe(...);
4646
// Your code here
4747
})(window.DDC.API);

source/includes/_samples.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ document.body.style.overflow = 'hidden';
1212
function sendResizeMessage() {
1313
window.parent.postMessage({
1414
type: 'IFRAME_HEIGHT_RESIZE',
15-
target: 'growing-iframe',
15+
target: 'test-integration-iframe', // Note: Replace 'test-integration-frame' with your actual iframe identifier.
1616
frameHeight: document.body.offsetHeight + 10 /* a little extra for good measure */
1717
}, '*');
1818
}
@@ -35,12 +35,12 @@ if (window.ResizeObserver) {
3535
3636
```javascript
3737
(function (WIAPI) {
38-
API = new WIAPI();
38+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
3939

4040
API.insert('content', function (elem, meta) {
4141
var iframeElem = document.createElement('iframe');
4242
iframeElem.src = 'https://www.yourdomain.com/path-to-iframe.htm';
43-
iframeElem.classList.add('my-integration-name-iframe');
43+
iframeElem.classList.add('test-integration-iframe'); // Note: Replace 'test-integration-frame' with your actual iframe identifier.
4444
API.append(elem, iframeElem);
4545
});
4646

@@ -66,7 +66,7 @@ if (window.ResizeObserver) {
6666

6767
An integration may want to insert an iframe that resizes as its contents change. One possible way to accomplish this is for the iframe and the integration to work together as shown in the sample code from the pane on the right side of this page. You can see the sample code running [here](https://webapitestddc.cms.dealer.com/growing-iframe-example.htm).
6868

69-
### iframe Responsibilities:
69+
### IFrame Responsibilities:
7070

7171
* **Determine when content dimensions change** - One way to do this is using [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver). `ResizeObserver` is not supported in IE11, so one possible solution is to fallback to polling. Polling is not ideal, but it will work for this small percentage of our traffic.
7272
* **Communicate the new dimension to the outer page** - iframes can communicate with the parent page using [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage).

source/includes/_utilities.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In addition to the event based system for working with sites, some utility metho
88
99
```javascript
1010
(function(WIAPI) {
11-
var API = new WIAPI();
11+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
1212
API.subscribe('vehicle-data-updated-v1', function(data) {
1313

1414
API.log(data.payload.pageData); // Logs the Page Data object
@@ -36,7 +36,7 @@ This can be used to obtain an array of attributes for the currently displayed ve
3636
3737
```javascript
3838
(function(WIAPI) {
39-
var API = new WIAPI('test-integration');
39+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier to obtain the correct configuration data.
4040
var testConfig = {
4141
dealerId: "12345",
4242
showOnSRP: true,
@@ -60,7 +60,7 @@ This fetches a JavaScript object of your integration's configuration for the cur
6060
6161
```javascript
6262
(function(WIAPI) {
63-
var API = new WIAPI();
63+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
6464
API.utils.getDealerData().then(function(dealerData) {
6565
// Logs the Dealership Info Event object for the current website.
6666
API.log(dealerData);
@@ -76,7 +76,7 @@ This fetches the <a href="#dealership-info-event">Dealership Info Event object</
7676
7777
```javascript
7878
(function(WIAPI) {
79-
var API = new WIAPI();
79+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
8080
API.utils.getJwtForVehicles().then(function(jwtObject) {
8181
API.log(jwtObject);
8282
// Returns a data structure like this:
@@ -96,7 +96,7 @@ This fetches an object containing the array of VINs on the current page and a co
9696
9797
```javascript
9898
(function(WIAPI) {
99-
var API = new WIAPI();
99+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
100100
API.utils.getPageData().then(function(pageData) {
101101
// Outputs the Page Data Object for the current page.
102102
API.log(pageData);
@@ -108,15 +108,29 @@ This fetches the <a href="#page-event">Page Event object</a> for the current web
108108

109109
## API.utils.getUrlParams()
110110

111-
NOTE: This method does not return a promise as the URL Params are immediately available and do not require Promise behavior.
111+
NOTE: This method returns immediately, not as a Promise, because the URL Params are already available and do not require asynchronous behavior.
112+
113+
Running this function at a URL such as this:
114+
115+
[https://www.roimotors.com/?query=This%20is%20the%20query&hello=world&foo=bar](https://www.roimotors.com/?query=This%20is%20the%20query&hello=world&foo=bar)
116+
117+
Will return the following object:
118+
119+
```{
120+
query: "This is the query",
121+
hello: "world",
122+
foo: "bar"
123+
}```
124+
112125
113126
> Usage:
114127
115128
```javascript
116129
(function(WIAPI) {
117-
var API = new WIAPI();
118-
var urlParams = API.utils.getUrlParams();
119-
API.log(urlParams); // Logs the configuration object for your integration (if there is one).
130+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
131+
var urlParams = API.utils.getUrlParams(); // Returns the current URL parameters as object attributes, so you can easily access the values.
132+
API.log(urlParams); // Log the entire object.
133+
API.log(urlParams.query); // Access just the `query` parameter, for example.
120134
})(window.DDC.API);
121135
```
122136

@@ -126,7 +140,7 @@ NOTE: This method does not return a promise as the URL Params are immediately av
126140
127141
```javascript
128142
(function(WIAPI) {
129-
var API = new WIAPI();
143+
var API = new WIAPI('test-integration'); // Note: Replace 'test-integration' with your actual integration identifier.
130144
var config = API.utils.getVehicleData().then(function(vehicleData) {
131145
// Outputs the current set of vehicle data.
132146
API.log(vehicleData);

0 commit comments

Comments
 (0)