# CrossIndie Godot SDK (Godot 4.x)

## Concepts

- **app_id**: the id of your app, shown in the dashboard under My Apps (https://crossindie.com/dashboard/apps). It is public; it goes into your app, game or site code.
- **App API key** (`api_key`): secret, used only for the account API and the MCP server. Never put it in a shipped app, game or web page.
- **api_base**: `https://api.crossindie.com`.
- **category**: `game`, `web_tool`, `saas` or `mobile_app`. Games are shown only to games; web tools and SaaS share a pool.
- Every placed banner is an independent earning slot. An impression only counts after the banner has been visible for at least 1.5 seconds (while the window or app is focused). All credit and anti-fraud checks run on the server.
- New apps may need review before they are served. Check the app status in the dashboard.
- An app is promoted only once it is live on a store. For Google Play and App Store links the package (`play_package`) or numeric id (`appstore_id`) is derived from `target_url`; CrossIndie checks store liveness every 12 hours and shows `store_status` (live, not_found, error, unknown). Web apps do not need a store listing.

## Install

1. Copy `addons/cross_indie/` from the SDK repo (https://github.com/Cross-Indie/sdks, folder `godot/`) into the project's `res://addons/`.
2. Enable it in Project > Project Settings > Plugins > CrossIndie.
3. Add a `CrossIndieBanner` node (it is a custom node type) to a UI scene.

## Configure

Exported properties: `api_base` (String), `app_id` (String), `category` (enum game | web_tool | saas | mobile_app), `auto_load` (bool, default true), `banner_format` (enum image | card | banner, default card).

```gdscript
@onready var banner := $CrossIndieBanner

func _ready() -> void:
    banner.api_base = "https://api.crossindie.com"
    banner.app_id = "YOUR_APP_ID"
    banner.category = "game"
    banner.banner_format = "card"
    banner.auto_load = false
    banner.ad_loaded.connect(func(ad_name): print("ad: ", ad_name))
    banner.ad_failed.connect(func(reason): push_warning(reason))
    banner.load_ad()
```

Method: `load_ad()`. Signals: `ad_loaded(ad_name: String)`, `ad_failed(reason: String)`, `impression_tracked`, `clicked`.

## Pitfalls

- The default `api_base` is `http://localhost:8000`. Always set it to `https://api.crossindie.com`.
- Set properties before `load_ad()`. With `auto_load = true` the ad is fetched in `_ready`, so set properties in the Inspector or before the node enters the tree.
- The node is a Control: give it a size (custom minimum size or a container). A zero-size node shows nothing.
- Impressions count only while `DisplayServer.window_is_focused()` is true and the node is visible.
- Web exports: requests are made from the browser, so the backend must allow your game's origin (CORS).
- Clicking opens the store page with `OS.shell_open()`.
