class Teak
All SDK functionality is exposed through an instance of the Teak class assigned to window.teak by the initialization snippit. Once the SDK is loaded, the class itself is accessible as window.teakClass.
Load the Teak JavasScript SDK on your page by inserting the following snipping after the <body> tag.
<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>
Static Attributes
NotificationState
Enum of possible states for Web Push.
| Name | Description |
|---|---|
|
The state of Web Push has either not been determined, or is unable to be determined due to a browser error. |
|
The player has granted Web Push permissions for the current site, and notifications may be sent. |
|
The player has denied Web Push permissions for the current site. Notifications may not be sent. |
|
No Service Worker is configured. Follow the steps in Add a Service Worker. |
|
Web Push is not supported by the current browser. |
|
The player has granted Web Push permissions for the current site, but for a different Web Push vendor or internal service. Teak cannot currently send Web Push notifications to the player, but could after calling registerForNotifications with the |
RewardStatus
RewardStatus indicates the disposition of a reward claim, if it was granted or if it was denied why it was denied.
Name |
Value |
Description |
|
"grant_reward" |
The reward was granted to the player, and the RewardEvent will have a populated |
|
"expired" |
The reward has expired and is no longer claimable |
|
"already_clicked" |
The player has already claimed this reward and cannot claim it again |
|
"too_many_clicks" |
This reward has a limit on the number of players who can claim it, and has reached that limit |
|
"self_click" |
This reward was shared by the current player, and cannot be claimed by them |
|
"exceed_max_clicks_for_day" |
This reward has a limit of the number of times it can be claimed by the player in a day, and the player has reached that limit |
|
"not_for_you" |
This reward has a restriction on which players can claim it, and the current player is not on the list |
|
"invalid_post" |
This reward was not recognized |
|
"player_ineligible" |
The player is not eligible to claim this reward (server-side validation failure under jwt claim mode) |
|
"no_reward_available" |
No reward is currently available for this player (server-side validation failure under jwt claim mode) |
|
"claim_mode_unsupported" |
The claim mode requested by the SDK is not supported for this reward |
Methods
init
Initializes the Teak SDK. This method must always be called first.
New integrations should use the opts-hash form (third argument is an options object). The legacy positional form is supported indefinitely for backward compatibility, but new options are added only to the opts hash. claimMode is opts-only — there is no positional slot for it.
// Preferred: opts-hash form
teak.init("YOUR_APP_ID", "YOUR_API_KEY", {
debug: false,
claimMode: "legacy"
});
// Legacy positional form (continues to work)
teak.init("YOUR_APP_ID", "YOUR_API_KEY", false);
Parameters
Name |
Type |
Description |
|
string |
Your Teak App Id |
|
string |
Your Teak API Key |
|
InitOptions | boolean | undefined |
Either an options hash (preferred) or, in the legacy positional form, the |
InitOptions
Name |
Type |
Description |
|
boolean | undefined |
Enable additional debug logging. Defaults to |
|
string | undefined |
Reward-claim mode reported with every click. Defaults to |
The opts-hash form treats null as an empty hash (all defaults) and ignores unknown keys. Detection: if the third argument is a plain object (not undefined, not a Boolean, not a Window) it is interpreted as an opts hash; otherwise the positional form is used.
login
Starts a session for a player. Required for reward claims, click tracking, and DAU. Most Teak functionality is unavailable until login is called.
Call login again to update player data during a session. Fields omitted from options are ignored; login never clears existing data.
Types
LoginOptions
Name |
Type |
Description |
|
string | undefined |
The player’s email address. |
|
string | undefined |
The player’s Facebook ID. The key is snake_case; |
|
string | Record<string, string | number> | undefined |
Overrides the attribution source for this session in place of |
queryParameters
Use when the URL Teak should inspect for attribution (teak_notif_id, teak_deep_link, etc.) is not the page’s own address bar — e.g. the game runs in an iframe, is an SPA that has already navigated, or receives the launch URL from a native wrapper.
Accepts:
-
String — a query string with or without a leading
?. URL-decoded per standard rules, so passlocation.searchraw. -
Object — plain key/value pairs, used as-is (do not pre-encode). Values are coerced to strings;
null/undefinedand inherited keys are skipped.
Replaces window.location.search entirely — the two are not merged. A teak_deep_link in the override still has its embedded params lifted into the attribution set.
Parameters
Name |
Type |
Description |
|
string |
A unique identifier for the current player |
|
LoginOptions | undefined |
Optional player data and per-session overrides. |
on
Registers a handler for a given event type.
The available event types are
-
reward: Fired when the SDK process a reward claim -
deepLink: Fired when the SDK process a deep link -
postLaunchSummary: Fired after the SDK initializes a session indicating the session attribution data
Types
PostLaunchSummaryEvent
Name |
Type |
Description |
|
string |
The URL of the current page |
|
string | undefined |
If the session started from a notification click, the name of the Schedule that was sent |
|
string | undefined |
If the session started from a notification click, the internal id of the Schedule that was sent |
|
string | undefined |
|
|
string | undefined |
|
|
string | undefined |
If the session started from a source with an associated reward, the internal id of that reward |
|
string | undefined |
If the session started through a Teak source, a string indicating the channel. This value may be set by the marketing team |
|
string | undefined |
If the session started from a source with an associated deep link, the raw URL of the deep link |
|
string | undefined |
If the session started from a notification click, the internal id of the originating send event |
|
string\ undefined |
If the session started from a notification click, the name of the opt out category configured for the message |
Parameters
Name |
Type |
Description |
|
"reward" | "deepLink" | "postLaunchSummary" |
The event type to register a listener for |
|
(RewardEvent | PostLaunchSummaryEvent | object) ⇒ void |
The listener callback to register |
registerForNotifications
Attempts to register the current site for Web Push notifications. If required, will prompt the player for permissions using the browser’s native permission dialog. This method should be called when you want to prompt the player for Web Push permissions.
Parameters
Name |
Type |
Description |
|
boolean |
If true, and if the site is registered for Web Push with a different vendor or internal service, will unsubscribe from that vendor and resubscribe with Teak. |
|
(state: NotificationState) ⇒ void |
After the player has granted or denied push permissions, called with the current state of Web Push for the site. |
getNotificationState
Retrieves the current state of Web Push notifications.
Parameters
Name |
Type |
Description |
|
(state: NotificationState) ⇒ void |
Called with the current state of Web Push for the site. |
scheduleNotificationWithPersonalization
Schedules a Local Notification for the current player.
Parameters
Name |
Type |
Description |
|
string |
The name of Local Schedule to send to the current player |
|
number |
The number of seconds from now to send the notification in |
|
Record<string, any> |
Additional data to template into the notification as Local Notification Tags |
|
(status: "ok" | "error", errors?: Record<string, string[]>) |
Called after the notification is scheduled. If |
cancelNotification
Cancels a previously scheduled Local Notification for the current player.
Parameters
Name |
Type |
Description |
|
string |
The name of Local Schedule to cancel for the current player |
|
(status: "ok" | "error", errors?: Record<string, string[]>) |
Called after the notification is canceled. If |
cancelAllNotifications
Cancels all previously scheduled Local Notifications for the current player.
setStringAttribute
Sets a string Player Property for the current player.
setNumberAttribute
Sets a number Player Property for the current player.
incrementEvent
Reports a Custom Event for the current player.
Note that Teak has dedicated events for and automatically tracks sessions, session time, and interactions with notifications, emails, and links from Teak. This method should be used for unique in game events, such as completing a level or spinning on a slot machine.
Teak’s custom event structure is a three tiered hierachy, e.g. complete → quest → fetchApple. Calling incrementEvent("complete", "quest", "fetchApple", 1) will increment the player’s event count for complete, complete → quest, and complete → quest → fetchApple by 1.
Parameters
Name |
Type |
Description |
|
string |
The identifier for the top level of the hierarchy, e.g. 'complete'. |
|
string |
The identifier for the second level of the hierarchy, e.g. 'quest'. |
|
string |
The identifier for the third level of the hierarchy, e.g. 'fetchApple' |
|
number |
How much to increase the event count by. Must be >= 1. |
registerRoute
Registers a deep link route. This is similar to a single page application router, and is used by Teak to take players to specific in game destinations from an apprpriately configured notification, email, or link.
Parameters
Name |
Type |
Description |
|
string |
The route to register a callback for. May contain splat parameters beginning with |
|
string |
A name to give the route, which will be displayed in the Teak dashboard, e.g. |
|
string |
Documentation of the route. Include a description of what it does and all parameters, e.g. |
|
(parmeters: Record<string, string>) ⇒ void |
A function called when a notification, email, or link navigates to this route. |