> For the complete documentation index, see [llms.txt](https://docs.storylane.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.storylane.io/~/changes/zoBSTTy9mExPnxjbf4Hi/analytics/integrations/cross-frame-events.md). Agents can also search and read this documentation through its [MCP server](https://docs.storylane.io/~gitbook/mcp).

# Cross-Frame Events

Send demo analytic events cross origin

You can now send Storylane demo analytics cross-frame to hosting website. If you are embedding storylane demo on your webpage, then real-time analytics events can now be subscribed on your webpage.  Some use-cases can be:

* Launching chat-window based on user action in demo
* Displaying demo-booking calendar based on user action
* Combine Storylane analytics with additional user info and send to your analytics stack

## **Implementation**

When Storylane demo is embedded on webpage then each user interaction will trigger an event that will be sent through [`window.postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). Below is example of event payload sent from Storylane demo iframe

```json
//Storylane sends these postMessage events from iframe to parent window
window.parent.postMessage(
{
  message: 'storylane-demo-event',
  payload: {
    event: 'step_view';
    demo: {
      id: string;
      url: string;
    };
    step: {
      id: string;
      index: number; // starts with 1  
    };
    flow: {
      id: string;
      name: string;
    };
   }
 },
'*'
)

```

You will subscribe to the above events like below in your webpage so it can be processed&#x20;

```json
window.addEventListener('message', (event) => {
  if (event.data.message === 'storylane-demo-event') {
    //do something here based on event type
    // 1. send event to GA, Amplitude, mixpanel etc
    // 2. open chat window
    // 3. open meeting calendar ..or anything else
  }
})
```

Below are different <mark style="color:blue;">`event.data.payload`</mark>for different analytic events sent from Storylane Demo

<pre class="language-json"><code class="lang-json">// sent when demo loads first time 
{
  <a data-footnote-ref href="#user-content-fn-1">event</a>: 'demo_open';
  demo: {
    id: string;
    url: string;
  };
}

// sent when a guided step (hotspot, walkthrough or modal) is displayed
{
  event: 'step_view';
  demo: {
    id: string;
    url: string;
  };
  step: {
    id: string;
    index: number; // starts with 1  
  };
  flow: {
    id: string;
    name: string;
  };
}

// sent when lead is captured through form or url params
{
  event: 'lead_identify';
  demo: {
    id: string;
    url: string;
  };
  lead: {
    email: string;
    [key: string]: string; // e.g. first_name, last_name, company, etc...
  }
}

// sent when user clicks on CTA in button to external url
{
  event: 'open_external_url';
  demo: {
    id: string;
    url: string;
  };
  step: {
    id: string;
    index: number; // starts with 1  
  };
  flow: {
    id: string;
    name: string;
  };
  target: {
    url: string;
  }
}

// sent when flow started by user
// You need to have multiple flow and <a data-footnote-ref href="#user-content-fn-1">checklist</a> configured for this
{
  event: 'flow_start';
  demo: {
    id: string;
    url: string;
  };
  flow: {
    id: string;
    name: string;
  };
}

// sent when last step in flow was viewed 
{
  event: 'flow_end';
  demo: {
    id: string;
    url: string;
  };
  flow: {
    id: string;
    name: string;
  };
}

</code></pre>

## **See example below of sending events to GA**

{% embed url="<https://jsfiddle.net/storylane/Lwotsvdr/>" %}

[^1]:


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.storylane.io/~/changes/zoBSTTy9mExPnxjbf4Hi/analytics/integrations/cross-frame-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
