Javascript API Integration


This integration with Interacty API will help you to extend your projects functionality. You can new features to your projects. Let's look at the example. After game over the user will be automatically redirected to the external page.

This code snipped demonstrates game complete event handling:

<div class="remix-app" hash="3a92afd6f10b03e7">
    <script src="https://p.interacty.me/l.js" async></script>
</div>
<script>
  function postInit(InteractyClient) {
    const interactyClient = new InteractyClient(%PUBLIC_KEY%)
    interactyClient.events.subscribe('block.memory.game-completed', function(event) {
        console.log('got event memory game-completed', event.payload)
    })
  }
</script>
<script async src="https://p.interacty.me/v1/sdk.umd.production.min.js?callback=postInit"></script>

First, you need embed project into your site. In Interacty account click on three dots icon next to the project and then:

Copy link -> Embed in your Website or LMS. Copy code in Install embed code area:

In your account settings find and copy Public API key:

Paste Public API key and add location redirect, so the final code is:

<div class="remix-app" hash="3a92afd6f10b03e7">
    <script src="https://p.interacty.me/l.js" async></script>
</div>
<script>
  function postInit(InteractyClient) {
    const interactyClient = new InteractyClient("jdxmcvzfg28z99t24a-p6o2-sog")
    interactyClient.events.subscribe('block.memory.game-completed', function(event) {
      console.log('got event memory game-completed', event.payload)
      window.location.href = "https://wikipedia.org/"
    })
  }
</script>
<script async src="https://p.interacty.me/v1/sdk.umd.production.min.js?callback=postInit"></script>

 

Done! Now after game completion a special API event will trigger and open a new url in the browser.

 

 


Was this article helpful?