Receiving events
Listen for postMessage events from the Spin Widget iframe.
The Spin Widget runs inside an iframe and posts messages to the parent window when the user interacts with it. The widget is served from spins.impel.ai. The legacy aliases spins.impel.io and spins.spincar.com may also be in use, so host pages should accept all three as valid origins.
Each Impel message is a string with a known prefix:
| Prefix | Format |
|---|---|
sts-post-analytics: | Prefix + JSON body, for example sts-post-analytics:{"event":"view_360_popout"} |
STS:FullBrowser:: | Prefix + string data (open or close) |
Quickstart listener
window.addEventListener('message', (event) => {
if (!/^https:\/\/spins\.(impel\.ai|impel\.io|spincar\.com)$/.test(event.origin)) return;
if (typeof event.data !== 'string') return;
const ANALYTICS_PREFIX = 'sts-post-analytics:';
if (event.data.indexOf(ANALYTICS_PREFIX) === 0) {
const message = JSON.parse(event.data.substring(ANALYTICS_PREFIX.length));
handleAnalyticsEvent(message.event, message.data);
return;
}
const FULLSCREEN_PREFIX = 'STS:FullBrowser::';
if (event.data.indexOf(FULLSCREEN_PREFIX) === 0) {
const action = event.data.substring(FULLSCREEN_PREFIX.length); // 'open' or 'close'
handleFullScreen(action);
return;
}
});Post analytics
Enable post-analytics to track user engagement with the widget (clicks, view changes, photo navigation) in your own analytics platform alongside your other site events.
Enable it by setting !postanalytics=<URL> in the URL fragment, where <URL> is the origin of the host page, for example https://www.exampledealer.com. The widget passes this URL as the targetOrigin argument to postMessage, so messages are delivered only to a parent at that origin.
| Event | Trigger | data |
|---|---|---|
view_360_popout | User clicks "View Full Screen" | — |
view_hotspots | User toggles hotspots on | — |
hide_hotspots | User toggles hotspots off | — |
view_interior | User switches to the interior view from the toggle | — |
view_exterior | User switches to the exterior view from the toggle | — |
click_360_exterior | User clicks or interacts with the exterior 360 spin | — |
click_360_interior | User clicks or interacts with the interior 360 spin | — |
click_photo_thumbnail | User clicks a photo thumbnail from the carousel | — |
view_photo | User views a photo in the Photo Viewer | {name} |
click_carousel_navigation_left | User clicks the carousel's left arrow | — |
click_carousel_navigation_right | User clicks the carousel's right arrow | — |
click_photoviewer_navigation_left | User clicks the Photo Viewer's left arrow | — |
click_photoviewer_navigation_right | User clicks the Photo Viewer's right arrow | — |
click_close_photoviewer | User closes the Photo Viewer | — |
Full screen
Enable full-screen messaging to let users expand the widget within their browser. The host page resizes the iframe in response to the messages.
Enable it by setting !enableWideScreenView (see Display and behavior).
| Data | Meaning |
|---|---|
open | User requested an expanded view |
close | User requested to return to the normal view |