Skip to content

Integrating the SDK

AdsCraft turns selected gameplay parameters into fields you can change on the web without rebuilding. The SDK does three jobs:

  1. Mark fields at build time — the @paField decorator records which properties are configurable.
  2. Apply config at runtime — the platform writes the saved values onto your components before onLoad() / start() runs, so your game reads them like any normal property.
  3. Expose the PA.* API — channel, CTA and lifecycle hooks, all network-agnostic.

Only Cocos Creator 3.x is supported (verified on 3.8.3 and 3.8.8). Cocos 2.4.x is not.

  • Cocos Creator 3.x installed.
  • A dashboard account. Sign in with Google at playground.adscraft.app — the first sign-in creates your own workspace. In a studio, accept your teammate’s invite before creating an App (why).
  • An App created on the dashboard — the extension uploads into an App but can’t create one.
  • The extension installed (step 1 below), then signed in from the panel’s Accounts tab.
Download the extension

Unzip it, then in Cocos Creator open Extension → Extension Manager → Import and pick the ads-craft/ folder inside.

  1. Unzip the download — you get an ads-craft/ folder.
  2. In Cocos Creator: Extension → Extension Manager → Import → pick that ads-craft/ folder.
  3. Restart Creator if it asks.

On activation the extension copies the SDK into assets/pa-sdk/ of your project. There is no npm install and no manual file copying. Import it with Cocos’s native scheme:

import { paField, PA } from 'db://assets/pa-sdk'

Decorate a property once, in code. @paField goes above @property:

import { _decorator, Component, AudioClip } from 'cc'
import { paField } from 'db://assets/pa-sdk'
const { ccclass, property } = _decorator
@ccclass('GameManager')
export class GameManager extends Component {
@paField({ section: 'Game Settings', label: 'Taps to win', min: 1, max: 50 })
@property
taps = 30
@paField({ section: 'Game Settings', label: 'Difficulty', options: ['easy', 'normal', 'hard'] })
@property
difficulty = 'normal'
@paField({ section: 'Sounds', label: 'Background music' })
@property(AudioClip)
bgm: AudioClip = null
start() {
// Already holds the value saved for this Creative — just read it normally.
this.tapsLeft = this.taps
}
}

@paField only records metadata: it does not change the value, wrap getters or touch runtime. Remove the platform and the game runs exactly as before, with the values in the Inspector.

Option Meaning
section Group heading on the web form. Default 'Default'.
label Label shown on the form. Default = property name.
order Position inside its section.
min / max Range for number fields. Enforced on the form and by the server.
step Number-input step (the server does not enforce step).
options Makes a select field; the value must be one of these strings.
enum Enum field: usually auto-detected, so set it only when the property has no @property({ type: Enum(X) }).
maxBytes Size cap for a user-replaced image/audio field.
help Hint shown next to the field.
type Force the field type. Rarely needed: image/audio are auto-detected from @property(SpriteFrame) / @property(AudioClip). Use FieldType.IMAGE / FieldType.AUDIO when the type is declared on a base class in another file and the scene has no asset assigned.

number, string, boolean, color ("#RRGGBB"), select (with options), image, audio, vec2, vec3, and json (when the underlying property is a JSON string — the web form expands it into sub-fields instead of making you type raw JSON).

image and audio come from the @property declaration: @property(SpriteFrame) → image, @property(AudioClip) → audio (@property({ type: X }) and the cc.-prefixed names work too). When the type is declared on a base class in another file, the SDK falls back to the __expectedType__ of the reference stored in the scene. If neither is available, the field is inferred as a plain string and a replaced file will not apply — mark it with type: FieldType.IMAGE / type: FieldType.AUDIO.

Enum: a property declared @property({ type: Enum(X) }) appears as a dropdown on the web and saves its numeric value — no @paField option needed. Add @paField({ enum: 'X' }) only when the property has no @property enum declaration. Numeric enums only.

Image/audio fields are split out of the compressed block at build time, so replacing one on the web replaces the original file in the package rather than carrying both versions.

  • Keep the sprite outside any auto-atlas and disable texture compression for it if you want in-place replacement. An atlas-packed or multi-variant texture still gets replaced on the web, but additively, which makes the package larger.
  • A replacement image must match the original size and aspect ratio. The tool neither fixes nor warns about a mismatch, and the sprite is stretched or cropped.
  • Audio can differ in length. Accepted audio: MP3, OGG, WAV, M4A — prefer MP3 or M4A. Images: PNG, JPEG or WebP (OGG breaks on older Safari).
  • Only parameters that live in the scene are detected. Parameters on prefabs spawned at runtime are not scanned in this MVP. Move the value onto a scene node first.
  • Save the scene before building. The extractor reads the .scene file on disk, not the scene open in the Editor — an unsaved scene yields stale values.
  • Only the startup scene is scanned. It is both the first scene played and the schema source — pick it in the panel’s Build & upload tab.
  • Do not rename or move a node that has @paField after you have uploaded a build and created a Creative. Fields are matched by node path (Cocos strips most real UUIDs during build), so renaming or moving breaks the saved config of every Creative using that build.
  • Duplicating an object shares its fields. Copies with the same name under the same parent share a node path, so the web shows one field per property and its value applies to every copy. Give the copies different names if you need to configure them separately.

The AdsCraft panel inside Cocos Creator runs the whole pipeline — Cocos build, schema extraction, asset compression, merge and upload — and shows the payload size against the cap before anything leaves your machine. It has its own guide: Using the Cocos extension.

A build that fails — over the size limit, or a Cocos build error — creates nothing on the dashboard. Over-limit builds are blocked before upload; each network has its own cap (Unity Ads ~4.94 MB payload because the finished package is 5 MB, ironSource 4 MB, GDT 3 MB, …). Reduce it with the Assets tab or lighter Cocos build settings.

The runtime applies the saved config before your game starts; read it through PA:

import { PA } from 'db://assets/pa-sdk'
start() {
const taps = PA.get('a1b2c3.taps', 30) // applied value, or the fallback when unset
if (PA.channel === 'Unity') { /* … */ }
PA.gameStart(() => { /* network told us the playable began */ })
PA.gameClose(() => { /* network told us the playable is closing */ })
}
onCTAButtonClick(): void {
PA.ctaClick() // fire the current network's CTA
}
onRoundEnd(): void {
PA.gameEnd() // round over
}
API Use
PA.channel Current network id (e.g. 'Unity'). 'none' outside a playable.
PA.get(fieldId, fallback) Read the applied value of a field; fallback when it is not set.
PA.ctaClick() Trigger the current network’s call-to-action.
PA.gameEnd() Round over.
PA.gameRetry() Player started a new round.
PA.gameStart(cb) Register a callback for when the network reports the playable started (Mintegral window.gameStart).
PA.gameClose(cb) Register a callback for when the network reports the playable closed (Mintegral window.gameClose).

Field ids are stable per build; read them from the schema in the extension rather than hard-coding. PA.get() takes the fallback as the second argument — always pass your default.

CTA integration — always use PA.ctaClick()

Section titled “CTA integration — always use PA.ctaClick()”
onCTAButtonClick(): void {
PA.ctaClick()
}

PA.ctaClick() is network-agnostic — use it for every CTA button. Outside a playable it is a safe no-op, so the same code runs in the Editor and on the web.

  • Config is applied before onLoad() / start(), so reading this.taps in start() is enough.
  • Image/audio replacements are preloaded before the startup scene launches, so onLoad() sees them.
  • The game is paused and muted while the ad is hidden (tab switch, visibilitychange, MRAID viewableChange) and resumed when visible again — no code required.

When you run the game in the Editor, or as a plain web build not generated by the platform, PA.* degrades to safe no-ops — no throws, nothing happens — and PA.channel is 'none'. @paField and PA.* never make your game “platform-only”.

An upload creates a Build plus a default Creative. From there, changing values, generating variants and downloading per-network packages all happen on the web — see Using the web dashboard.