Integrate on web, PC, Unity and mobile
Pick your platform.
Pick your platform. All of them use the same Spot, the same rules and the same payouts.
Website#
Use the script from the install guide. It works in any site builder that lets you add an HTML block or a script tag, and in single-page apps: add the script once in the page that should show the frame.
<script src="https://offers.kre8.fun/widget/offerwall.js" data-placement="pk_YOUR_SPOT_KEY" async></script>import { useEffect, useRef } from 'react'
export function EarnFrame() {
const host = useRef(null)
useEffect(() => {
const s = document.createElement('script')
s.src = 'https://offers.kre8.fun/widget/offerwall.js'
s.async = true
s.dataset.placement = 'pk_YOUR_SPOT_KEY'
s.dataset.target = '#earn-frame'
document.body.appendChild(s)
return () => s.remove()
}, [])
return <div id="earn-frame" ref={host} />
}PC games and desktop apps#
Create a Spot with the PC platform. Show offers in your launcher or menu by opening the popup page in an embedded web view, or call the same web endpoints from your own interface:
# list offers for your Spot (public)
curl "https://offers.kre8.fun/v1/offers?placement=pk_YOUR_SPOT_KEY"
# start one for a signed-in player
curl -X POST https://offers.kre8.fun/v1/offers/OFFER_ID/start \
-H "authorization: Bearer PLAYER_GULLY_ID_TOKEN" -H "content-type: application/json" \
-d '{"placement":"pk_YOUR_SPOT_KEY"}'Players sign in with Gully ID. Rewards are claimed from the claim page the answer points to.
Unity#
Two things matter for games:
- Play time. Send the seconds a player has played, from the game client. The service clamps the number to real time, so it cannot be inflated.
- Game events. Your game server sends a signed event when something happens (level reached, match won). Matching offer steps complete.
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class SwoopPlaytime : MonoBehaviour {
const string Api = "https://offers.kre8.fun";
public string offerId, gullyIdToken, session;
public IEnumerator Send(int seconds) {
var json = "{\"session\":\"" + session + "\",\"seconds\":" + seconds + "}";
var req = new UnityWebRequest(Api + "/v1/actions/offers/" + offerId + "/playtime", "POST");
req.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(json));
req.downloadHandler = new DownloadHandlerBuffer();
req.SetRequestHeader("content-type", "application/json");
req.SetRequestHeader("authorization", "Bearer " + gullyIdToken);
yield return req.SendWebRequest();
Debug.Log(req.downloadHandler.text);
}
}import { createHmac, randomUUID } from 'node:crypto'
const body = JSON.stringify({ offerId: 'OFFER_ID', userId: 'PLAYER_ID', event: 'level_reached', value: 10 })
const ts = Math.floor(Date.now() / 1000).toString()
const nonce = randomUUID()
const sig = createHmac('sha256', process.env.SPOT_SECRET).update(`${ts}.${nonce}.${body}`).digest('hex')
await fetch('https://offers.kre8.fun/v1/actions/events', {
method: 'POST',
headers: { 'content-type': 'application/json', 'x-gully-key': 'pk_YOUR_SPOT_KEY', 'x-gully-timestamp': ts, 'x-gully-nonce': nonce, 'x-gully-signature': sig },
body,
})Keep your Unity project private: Asset Store packages must never be published. The Spot secret belongs on the game server only, never in the client build.
iOS and Android#
Create a Spot with the iOS or Android platform. Mobile Spots run offers as points only, and promoted coins never show on them, as the app stores require. Show the frame in a web view, or draw your own list from the offers endpoint above.
// Android (Kotlin): show the frame in a WebView
webView.settings.javaScriptEnabled = true
webView.loadUrl("https://offers.kre8.fun/widget/frame?placement=pk_YOUR_SPOT_KEY")// iOS (Swift): show the frame in a WKWebView
let url = URL(string: "https://offers.kre8.fun/widget/frame?placement=pk_YOUR_SPOT_KEY")!
webView.load(URLRequest(url: url))Reward notifications (postbacks)#
Set a reward callback URL on your Spot and the service tells your server whenever a step is earned or reversed. Every call is signed so you can trust it.
import { createHmac, timingSafeEqual } from 'node:crypto'
// raw = the request body as received (a Buffer or string), never re-serialised
export function checkNotification(headers, raw, secret) {
const ts = Number(headers['x-gully-timestamp'])
if (!Number.isFinite(ts) || Math.abs(Date.now() / 1000 - ts) > 300) return false
const want = createHmac('sha256', secret).update(`${ts}.${headers['x-gully-nonce']}.${raw}`).digest()
const got = Buffer.from(String(headers['x-gully-signature']), 'hex')
return got.length === want.length && timingSafeEqual(got, want)
}import hmac, hashlib, time
def check_notification(headers, raw: bytes, secret: str) -> bool:
ts = int(headers["x-gully-timestamp"])
if abs(time.time() - ts) > 300:
return False
msg = f"{ts}.{headers['x-gully-nonce']}.".encode() + raw
want = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(want, headers["x-gully-signature"])<?php
function check_notification(array $h, string $raw, string $secret): bool {
$ts = (int)$h['x-gully-timestamp'];
if (abs(time() - $ts) > 300) return false;
$want = hash_hmac('sha256', "$ts." . $h['x-gully-nonce'] . "." . $raw, $secret);
return hash_equals($want, $h['x-gully-signature']);
}Answer with a 2xx status. Retries use the same event id in X-Gully-Event-Id, so save it and ignore repeats.