Install the Teak JavaScript SDK

It’s time to add the Teak JavaScript SDK to your web game.

  • Teak supports Chrome 42+, Edge 17+, Firefox 44+, Opera 20+, and Safari 16+.

Add the Teak SDK to your page

In the <body> of your game’s web page, add the following code:

<script type="text/javascript">
(function(){window.teak=window.teak||[];window.teak.methods=["init","on","login","registerForNotifications","getNotificationState","incrementEvent","scheduleNotificationWithPersonalization","cancelNotification","cancelAllNotifications","setStringAttribute","setNumberAttribute","scheduleLongDistanceNotification","deleteEmail","setChannelState","setCategoryState", "registerRoute"];window.teak.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);window.teak.push(t);return window.teak}};for(var e=0;e<window.teak.methods.length;e++){var t=window.teak.methods[e];if(!window.teak[t]){window.teak[t]=window.teak.factory(t)}}})();
(function(){var n=document.createElement("script");n.type="text/javascript";n.async=true;n.src="//sdks.teakcdn.com/teak.min.js";var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)})();
</script>

Add a Service Worker

For Web Push support your site must have a registered Service Worker. If you already have one, skip ahead to Add the Teak SDK to your Service Worker.

Create a file named sw.js in the root folter of your webiste with the following content

importScripts('https://sdks.teakcdn.com/teak.service_worker.min.js')

Then register the service worker for your website by adding the following code immediately after <body>

<script type="text/javascript">
navigator.serviceWorker.register('/sw.js', { scope: '/', updateViaCache: 'none' });
</script>

Add the Teak SDK to your Service Worker

If you have an existing Service Worker, add the following line to it

importScripts('https://sdks.teakcdn.com/teak.service_worker.min.js')

Initialize the Teak SDK

Next, we’ll need to initialize the Teak SDK with your game’s Teak App ID and Teak API Key. If you don’t have an app in Teak, you need to create a new game.

  1. On your Teak Dashboard, navigate to Settings  General.

  2. Add the codeblock below to a <script> tag on your page, and copy the Teak App ID and Teak API Key into it

    window.teak.init("YOUR_TEAK_APP_ID", "YOUR_TEAK_API_KEY")