PoseTracker API
  • PoseTracker integration
  • Webview/iframe tracking in app
    • â„šī¸How does it work ?
    • đŸ’ģTry it yourself
    • âš™ī¸Integration tutorials
      • 📱Expo React Native example
      • đŸ’ģVanilla HTML & JS example
      • 🆕iOS SwiftUI example
      • 🆕Android Kotlin example
      • 🆕Flutter example
      • 🔜More to come...
    • 👨‍đŸ’ģTracking Endpoint params
      • 🔐TOKEN (required)
      • đŸ”ĨBLAZEPOSE (optional)
      • 📱WIDTH (optinal)
      • 📱HEIGHT (optinal)
      • đŸĨ”DIFFICULTY (optinal)
      • đŸ’ģ[developer plan only] KEYPOINTS
      • đŸ’ģ[developer plan only] ANGLES
      • đŸ’ĒEXERCISE (optional)
        • Squat
        • Lunge
        • Plank
        • Push Up
        • Balance on left leg
        • Balance on right leg
        • Split
        • Needle
        • đŸĻ•More to come...
      • đŸ–Ĩī¸SKELETON (optinal)
    • â„šī¸Tracking Endpoint Message to handle
      • đŸŽĻExercise Placement
      • đŸ”ĸExercise Counter
      • đŸ”ĸ[developer plan] Exercise Progression
      • đŸ”ĸ[developer plan] Tracking keypoints positions
      • đŸ”ĸ[developer plan] Tracking angles during movements
      • đŸ”ĸ[developer plan] Real-time motion feedbacks and recommandations
  • Pixel tracking
    • How does it work ?
    • First steps
    • Integration tutorials
      • 📱React Native example with react-native-vision-camera
      • đŸ’ģVanilla HTML & JS example
      • 🔜More to come...
    • 👨‍đŸ’ģPixel Endpoint params
    • â„šī¸Pixel message to handle
      • đŸŽĻExercise Placement
      • đŸ”ĸExercise Counter
      • đŸ”ĸ[developer plan] Exercise Progression
      • đŸ”ĸ[developer plan] Tracking keypoints positions
      • đŸ”ĸ[developer plan] Tracking angles during movements
      • đŸ”ĸ[developer plan] Real-time motion feedbacks and recommandations
    • đŸ› ī¸Support
Powered by GitBook
On this page
  1. Webview/iframe tracking in app
  2. Integration tutorials

Vanilla HTML & JS example

How to use PoseTracker in a vanilla html page ?

PreviousExpo React Native exampleNextiOS SwiftUI example

Last updated 9 months ago

Base on the schema on How does it work ? You need to call our URL 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 modify your API_KEY :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PoseTracker Camera Access</title>
    <style>
        #poseTrackerFrame {
            width: 350px;
            height: 350px;
            border: none;
        }
        #infoDisplay {
            margin-top: 20px;
        }
    </style>
</head>
<body>
<iframe 
  id="poseTrackerFrame"
  src="https://app.posetracker.com/pose_tracker/tracking?token=&exercise=squat&difficulty=easy&width=350&height=350&progression=true"
  allow="camera *;" 
/>
<div id="infoDisplay">Allow camera and wait few secondes.</div>
<div id="progression">Squat : 0 %</div>
<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);
    }
  }
</script>
</body>
</html>

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=API_KEY" you need to set your own API_KEY

🟧 Important point : Data 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);
    }
  }

Result

You can find source files here

You can find all the informations returned by

âš™ī¸
đŸ’ģ
https://app.posetracker.com/pose_tracker/tracking
PoseTracker here.
GitHub - Movelytics/HtmlJSPoseTrackerDemoGitHub
Logo