Quick Start and Usage Requirements

Quick Start

Get started with the SightMap Metrics API. To add SightMap Metrics to your web analytics environment, check out our 2-page guide here and explore the details below.

🏎️ For a really quick start, see our working examples below 🏎️

A working example integrating the API with an example SightMap instance is below. You may insert following usage examples within this HTML document in order to explore the API.

🚧

Setting the origin value

Set the origin query parameter to the origin serving the document. The example uses http://localhost:3000, however please update the value accordingly.

If you need to start a local server, the following gist provides instructions for doing so quickly on either Mac or PC: https://gist.github.com/jgravois/5e73b56fa7756fd00b89.

For security reasons, the example must be served from an origin and will not function correctly when directly opened in a Browser.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>SightMap JavaScript IFrame API Example</title>
    <style type="text/css">
        * {
            box-sizing: border-box;
        }
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <!-- The API script must be included on the page -->
    <script src="https://sightmap.com/embed/api.js"></script>

    <!--
    Include the IFrame embed code. The embed URL must include `enable_api=1` and 
    provide the pages origin, the example uses `http://localhost:3000`, however
    update this accordingly. Additionally, the iframe must declare an id
    attribute, in this case it is set to `sightmap`.
    -->
    <iframe id="sightmap" src="https://sightmap.com/embed/ryzvg6mywln?enable_api=1&origin=http://localhost:3000" frameborder="0" width="100%" height="100%"></iframe>

    <script type="text/javascript">
        // Create a new embed instance, providing the IFrame id value:
        var embed = new SightMap.Embed('sightmap');

        // Usage example code goes here...
    </script>
</body>
</html>

Usage Requirements

In order to use the SightMap JavaScript IFrame API, the page must include the following script tag prior to the embed code.

<!-- The API script must be included on the page -->
<script src="https://sightmap.com/embed/api.js"></script>

The embed url must also pass parameters to enable the API and specify the web page origin. An id must also be declared, to be referenced when initializing the Embed object.

<iframe id="sightmap" src="https://sightmap.com/embed/dgow3krqp2m?enable_api=1&origin=http://localhost:3000" frameborder="0" width="100%" height="100%"></iframe>

Examples

The following JSFiddle demonstrates how you can listen for metrics events. In this case, the events are logged to the console. There is also a commented out code snippet at the bottom showing you can push the event data to a GTM datalayer.

📘

The Metrics API only exposes the metric data, so it can be made compatible with any analytics platform.

Google Analytics (GA4)

The following is a fully working example integrating Google Analytics (GA4) with the Metrics API. Simply find and replace the example Google tag ID G-0JXFPKZHVY with your own. You'll also need update the origin query parameter on the iframe source URL – refer to the Quick Start section above for more on this parameter.

You can also review this example working in a Code Sandbox.

📘

The Metrics API only exposes the metric data, so it can be made compatible with any analytics platform.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>
      SightMap Metrics API Example
    </title>
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-0JXFPKZHVY"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag("js", new Date());
      gtag("config", "G-0JXFPKZHVY");
    </script>
    <script src="https://sightmap.com/embed/api.js"></script>
  </head>
  <body>
    <div tabindex="0" class="sightmap-container">
      <iframe
        id="sightmap"
        src="https://sightmap.com/embed/yzvgdok1vln?enable_api=1&origin=http://localhost:3000"
        frameborder="0"
        width="100%"
        height="900px"
      >
      </iframe>
    </div>
    <script>
      //intro to metrics api to ensure Sightmap is loaded and ready for events
      document.addEventListener("DOMContentLoaded", function (event) {
        const embed = new SightMap.Embed("sightmap");
        console.log(embed);
        embed.on("ready", function () {
          console.log("SightMap is ready");
          //metrics.unitDetails.apply.click 
          embed.on("metrics.unitDetails.apply.click", function (event) {
            const unitNumber = event.data.unit.unitNumber;
            const eventName = `Apply Click - Unit ${unitNumber}`;
            gtag("event", eventName);
          });
          //metrics.unitlist.unit.click
          embed.on("metrics.unitList.unit.click", function (event) {
            const unitNumber = event.data.unit.unitNumber;
            const eventName = `Unit List Click - Unit ${unitNumber}`;
            gtag("event", eventName);
          });
          //metrics.unitmap.unit.click
          embed.on("metrics.unitMap.unit.click", function (event) {
            const unitNumber = event.data.unit.unitNumber;
            const eventName = `Unit Map Click - Unit ${unitNumber}`;
            gtag("event", eventName);
          });
          //metrics.unitmatches.impression
          embed.on("metrics.unitMatches.impression", function (event) {
            const eventName = "SightMap Unit Matches View";
            gtag("event", eventName);
          });
          //metrics.unitlist.impression
          embed.on("metrics.unitList.impression", function (event) {
            const eventName = "SightMap Unit List View";
            gtag("event", eventName);
          });
          //metrics.unitlist.change
          embed.on("metrics.unitList.change", function (event) {
            const eventName = "SightMap Unit List Change";
            gtag("event", eventName);
          });
          //metrics.unitDetails.outbound.click
          embed.on("metrics.unitDetails.outbound.click", function (event) {
            const unitNumber = event.data.unit.unitNumber;
            const ctaName = event.data.label;
            const eventName = `CTA Click - ${ctaName} - Unit ${unitNumber}`;
            gtag("event", eventName);
          });
        });
      });
    </script>
  </body>
</html>

What’s Next