Skip to content

Media Viewer Events

By , Customer Success DirectorUpdated

Open this page in a new chat

Short answer

Sirv Media Viewer fires events when a viewer, spin, zoom, video or image is ready or used, such as spin:ready or zoom:zoomIn. Attach handlers with Sirv.on() and Sirv.off(), with addEventListener using sirv: names, or with jQuery. Use them to track how people use your media, for example in Google Analytics.

After reading this you will know

  • Which events Sirv Media Viewer fires
  • How to attach and remove event handlers
  • How spin views are counted

You can hook into the events below to track users and generate analytics that reveal how users are interacting with your Sirv Media Viewer images, spins and sliders.

EventParameterDescription
viewer:readyviewerFires when slider instance is ready to operate
viewer:fullscreenInviewerFires when slider instance is ready to operate
viewer:fullscreenOutviewerFires after exiting fullscreen
viewer:beforeSlideInnext itemFires before slide transition
viewer:beforeSlideOutcurrent itemFires before slide transition
viewer:afterSlideIncurrent itemFires after slide transition
viewer:afterSlideOutitemFires after slide transition
viewer:enableItemitemFires when item is enabled
viewer:disableItemitemFires when item is disabled
EventParameterDescription
spin:initspinFires when spin instance is initialized
spin:readyspinFires when spin instance is ready to operate
spin:zoomInspinFires when zoom mode activates
spin:zoomOutspinFires when zoom mode deactivates
spin:rotatespinFires when spin rotates (autorotate or user rotate)
spin:rotateEndspinFires when spin stops rotating
EventParameterDescription
zoom:readyzoomFires when zoom instance is ready to operate
zoom:zoomInzoomFires when zoom mode activates
zoom:zoomOutzoomFires when zoom mode deactivates
EventParameterDescription
video:readyvideoFires when video instance is ready to operate
video:playvideoFires when video playback starts
video:pausevideoFires when video playback is paused
video:resumevideoFires when video playback resumes
video:endvideoFires when playback reaches end of video
video:seekvideoFires when a seek operation completes
video:fullscreenInvideoFires when video enters fullscreen mode
video:fullscreenOutvideoFires when video leaves fullscreen mode
EventParameterDescription
image:readyimageFires when image instance is ready to operate

Sirv Media Viewer sends events to stats.sirv.com.

They will be shown in the Analytics section of app.sirv.com in the future but you can capture these events now in Google Analytics (for example through Google Tag Manager) or other analytics tools, via the JavaScript addEventListener API.

Example:

document.addEventListener('sirv:viewer:stats', e => {
console.log(e.detail.statsData);
});

Different events can contain different data. This is what data sent for the sessionStart event looks like:

e.detail.statsData = {
browser: {
width: 892,
height: 823
},
screen: {
width: 1512,
height: 982,
availWidth: 1512,
availHeight: 950,
colorDepth: 30,
pixelDepth: 30
}
name: "sessionStart",
origin: "///demo.sirv.com/example.spin",
sessionId: 3415941547,
ts: 1757498189424,
type: "spin"
};

Attach and remove event handlers with the Sirv API using Sirv.on() and Sirv.off() methods.

function viewerEventHandler(viewer) {
console.log('Sirv Viewer event happened.');
}
// Attach an event handler for a Viewer event
Sirv.on('viewer:ready', viewerEventHandler);
// Remove an event handler for a Viewer event
Sirv.off('viewer:ready', viewerEventHandler);
// Attach an event handler for a Spin event
Sirv.on('spin:zoomIn', (spin) => {
console.log('Spin frame is zoomed in.');
});
// Attach an event handler for a Zoom event
Sirv.on('zoom:zoomOut', (zoom) => {
console.log('Zoom image is zoomed out.');
});

In more detail:

<div class="Sirv" id="test">
<div data-src="https://demo.sirv.com/tshirt-blue.spin"></div>
<div data-src="https://demo.sirv.com/tshirt-green.spin"></div>
<div data-src="https://demo.sirv.com/tshirt-red.spin"></div>
</div>
<script type="text/javascript" src="https://scripts.sirv.com/sirvjs/v3/sirv.js"></script>
<script type="text/javascript">
Sirv.on('viewer:ready', (viewer) => {
console.log('custom global event ready', viewer);
if (viewer.id === 'test') {
let child = viewer.child();
}
});
Sirv.on('viewer:fullscreenIn', (viewer) => {
console.log('custom global event fullscreenIn', viewer);
});
Sirv.on('viewer:fullscreenOut', (viewer) => {
console.log('custom global event fullscreenOut', viewer);
});
Sirv.on('viewer:beforeSlideIn', (item) => {
console.log('custom global event beforeSlideIn', item);
});
Sirv.on('viewer:beforeSlideOut', (item) => {
console.log('custom global event beforeSlideOut', item);
});
Sirv.on('viewer:afterSlideIn', (item) => {
console.log('custom global event afterSlideIn', item);
});
Sirv.on('viewer:afterSlideOut', (item) => {
console.log('custom global event afterSlideOut', item);
});
</script>

Attach and remove event handlers with the standard DOM API by using the .addEventListener() and .removeEventListener() methods. Event names are namespaced with sirv:.

Attach an event handler for an event to a specific Sirv Media Viewer instance:

document.querySelector('.product-view .Sirv').addEventListener('sirv:viewer:beforeSlideIn', (e) => {
console.log('Sirv Viewer event happened.', e.detail);
});

Attach an event handler for an event to a document element to watch events from all Sirv Media Viewer instances:

document.addEventListener('sirv:viewer:beforeSlideIn', (e) => {
});

Attach and remove event handlers with jQuery using its .on() and .off() methods. Event names are namespaced with sirv::

function eventHandler(e) {
console.log('Sirv event happened.', e.detail);
}

Attach an event handler:

jQuery('.product-view .Sirv').on('sirv:viewer:beforeSlideIn', eventHandler);

Remove an event handler:

jQuery('.product-view .Sirv').off('sirv:viewer:beforeSlideIn', eventHandler);

Below shows the possible use of the spin:rotate event:

Sirv.on('spin:rotate', (spinInstance) => {
/* Send a spin event to Google analytics */
ga('event', {
'Sirv',
'Spin interaction',
eventLabel: 'event.sirv.spin.interaction'
});
/* Send a custom spin event to Facebook */
fbq('trackCustom', Sirv Spin Interaction');
});

Below shows two spins on a page, with different events applied per spin:

<div class="Sirv" id="viewer-id-1">
<div data-id="spin-id-1" data-src="https://demo.sirv.com/boot.spin"></div>
</div>
<div class="Sirv" id="viewer-id-2">
<div data-id="spin-id-2" data-src="https://demo.sirv.com/cap.spin"></div>
</div>
<script>
// first variant
Sirv.on('spin:ready', (spin) => {
// const viewer = spin.parent().parent()
// viewer.id === "viewer-id-1" || viewer.id === "viewer-id-2"
// spin.id === "spin-id-1 || spin.id === "spin-id-2"
display3dProductContent(spin);
});
Sirv.on('spin:rotate', (spin) => {
// const viewer = spin.parent().parent()
// viewer.id === "viewer-id-1" || viewer.id === "viewer-id-2"
// spin.id === "spin-id-1 || spin.id === "spin-id-2"
$('.slide-content').removeClass('show');
});
Sirv.on('spin:rotateEnd', (spin) => {
// const viewer = spin.parent().parent();
// viewer.id === "viewer-id-1" || viewer.id === "viewer-id-2"
// spin.id === "spin-id-1 || spin.id === "spin-id-2"
display3dProductContent(spin);
});
//second variant
document.querySelector("#viewer-id-2").addEventListener('sirv:spin:ready', (e) => {
const spin = e.detail;
// const viewer = spin.parent().parent();
// viewer.id === "viewer-id-2"
// spin.id === "spin-id-2"
});
document.querySelector("#viewer-id-2").addEventListener('sirv:spin:rotate', (e) => {
const spin = e.detail;
// const viewer = spin.parent().parent();
// viewer.id === "viewer-id-2"
// spin.id === "spin-id-2"
});
document.querySelector("#viewer-id-2").addEventListener('sirv:spin:rotateEnd', (e) => {
const spin = e.detail;
// const viewer = spin.parent().parent();
// viewer.id === "viewer-id-2"
// spin.id === "spin-id-2"
});
</script>

Sirv counts the views of your spins and shows the total on the Spin views page in your Sirv account.

A “view” is counted each time the spin:ready event fires. The event fires once the images have downloaded and the spin is ready to interact with.

Spins will lazy load by default, so the images will download only when the spin enters the viewport.

If the spin is further down the page, or in a gallery and not shown on load, no view will be counted until the user scrolls down to the spin.

If the user navigates to another page and then comes back to the same page, another spin view will be counted (once the spin:ready event fires).

Back to top