# Embed Usage Tracking and Events

This is only available as part of a paid subscription. More details at https://katacoda.com/embed/

When embedding Katacoda, events are raised when the user performs certain actions such as starting the scenario or moving to the next step. This allows you to push the metrics into your own analytics and marketing systems

# Snippet Example

Include the following snippet to listen for all events from the Katacoda.com domain.

<script type="text/javascript">
  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var windowEvent = window[eventMethod];
  var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";

  windowEvent(messageEvent,function(e) {
  var d = e.data;
  if(e && e.origin && e.origin.indexOf('katacoda.com') >= 0) {
    var t = {
      'event': 'katacoda-scenario',
      'eventName': "katacoda-" + d.scenario,
      'eventAction': d.action,
      'eventLabel': d.label
    }
    console.log("Katacoda Event", d, t);
  }
  },false);

</script>

# Event Data Examples

The events raised are as follows.

{action: "start", scenario: "1", label: undefined}
{action: "step", scenario: "1", label: "step1"} 
{action: "step", scenario: "1", label: "step2"}
{action: "step", scenario: "1", label: "step3"}
{action: "step", scenario: "1", label: "step4"}
{action: "step", scenario: "1", label: "step5"}
{action: "step", scenario: "1", label: "step6"} 
{action: "last_step", scenario: "1", label: undefined}
{action: "finish", scenario: "1", label: undefined} 
{action: "cta_clicked", scenario: "1", label: undefined} 

# Live Example

Open the developer console of the browser. When using the scenario the events raised from Katacoda will be outputted to the browser's console.