> For the complete documentation index, see [llms.txt](https://posetracker.gitbook.io/posetracker-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://posetracker.gitbook.io/posetracker-api/use-posetracker-on-real-time-camera-webcam/integration-tutorials/vanilla-html-and-js-example.md).

# Vanilla HTML & JS example

Base on the schema on [How does it work ?](/posetracker-api/use-posetracker-on-real-time-camera-webcam/how-does-it-work.md) You need to call our URL <https://app.posetracker.com/pose_tracker/tracking> through a **iframe.**

**Base on this here is a tutorial to use PoseTracker in a web app :**

#### Create an HTML file

```
touch test.html
```

#### Integrate PoseTracker

Copy/past this in your test.html and <mark style="color:red;">**modify your API\_KEY**</mark> :

<pre><code>&#x3C;!DOCTYPE html>
&#x3C;html lang="en">
&#x3C;head>
    &#x3C;meta charset="UTF-8">
    &#x3C;meta name="viewport" content="width=device-width, initial-scale=1.0">
    &#x3C;title>PoseTracker Camera Access&#x3C;/title>
    &#x3C;style>
        #poseTrackerFrame {
            width: 350px;
            height: 350px;
            border: none;
        }
        #infoDisplay {
            margin-top: 20px;
        }
    &#x3C;/style>
&#x3C;/head>
&#x3C;body>
<strong>&#x3C;iframe 
</strong>  id="poseTrackerFrame"
  src="https://app.posetracker.com/pose_tracker/tracking?token=<a data-footnote-ref href="#user-content-fn-1">API_KEY</a>&#x26;exercise=squat&#x26;difficulty=easy&#x26;width=350&#x26;height=350&#x26;progression=true"
  allow="camera *;" 
/>
&#x3C;div id="infoDisplay">Allow camera and wait few secondes.&#x3C;/div>
&#x3C;div id="progression">Squat : 0 %&#x3C;/div>
&#x3C;script>
  window.addEventListener('message', function(event) {
    if (event.origin !== "https://app.posetracker.com") return;

    const data = JSON.parse(event.data);
    updateInfoDisplay(data);
  });

  function updateInfoDisplay(info) {
    const infoDisplay = document.getElementById('infoDisplay');
    const progress = document.getElementById('progression');

    // Sorry for that x)
    if (info.type === 'counter') {
      infoDisplay.textContent = 'Counter: ' + info.current_count;
    } else if (info.type === 'progression') {
      progress.textContent = "Squat : " + info.value + " %"
    } else if (info.type === 'posture') {
      infoDisplay.textContent = info.placementMessage
    } else if (info.type === 'initialization') {
      infoDisplay.textContent = info.message
    } else {
      infoDisplay.textContent = 'Info received: ' + JSON.stringify(info);
    }
  }
&#x3C;/script>
&#x3C;/body>
&#x3C;/html>
</code></pre>

#### How does it works ?

* First we have the iframe :

```
<iframe 
  id="poseTrackerFrame"
  src="https://app.posetracker.com/pose_tracker/tracking?token=API_KEY&exercise=squat&difficulty=easy&width=350&height=350&progression=true"
  allow="camera *;" 
/>
```

In src="<https://...?token=><mark style="color:red;">API\_KEY</mark>" you need to set your own API\_KEY

#### 🟧 Important point : D**ata exchange between PoseTracker and your web app 🟧**

PoseTracker page will send information with a poseMessage so you can handle then like this

```
window.addEventListener('message', function(event) {
    // First check if the message come from posetracker
    if (event.origin !== "https://app.posetracker.com") return;

    const data = JSON.parse(event.data);
    updateInfoDisplay(data);
  });
```

#### Then you can handle data received :

```
function updateInfoDisplay(info) {
    const infoDisplay = document.getElementById('infoDisplay');
    const progress = document.getElementById('progression');

    // Sorry for that x)
    if (info.type === 'counter') {
      infoDisplay.textContent = 'Counter: ' + info.current_count;
    } else if (info.type === 'progression') {
      progress.textContent = "Squat : " + info.value + " %"
    } else if (info.type === 'posture') {
      infoDisplay.textContent = info.placementMessage
    } else if (info.type === 'initialization') {
      infoDisplay.textContent = info.message
    } else {
      infoDisplay.textContent = 'Info received: ' + JSON.stringify(info);
    }
  }
```

You can find all the informations returned by [PoseTracker here.](/posetracker-api/use-posetracker-on-real-time-camera-webcam/tracking-endpoint-message-to-handle.md)

#### Result

{% embed url="<https://youtu.be/12zcKJmqbx0>" %}

#### You can find source files here

This repo is kept as a reference implementation on GitHub.

We’ll clean and stabilize it over time.

It will remain available as sample code for integration.

{% embed url="<https://github.com/Movelytics/HtmlJSPoseTrackerDemo/tree/main>" %}

[^1]: Set your own <mark style="color:red;">**API\_KEY 🙏**</mark>


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://posetracker.gitbook.io/posetracker-api/use-posetracker-on-real-time-camera-webcam/integration-tutorials/vanilla-html-and-js-example.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
