# CrossIndie Unity SDK (uGUI)

## 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

Package Manager > Add package from disk > `com.crossindie.banner/package.json` from https://github.com/Cross-Indie/sdks (folder `unity/`), or copy `com.crossindie.banner` into the project's `Packages/`. Works from Unity 2021.3 LTS.

## Usage

1. Create a UI `RawImage` where the banner should appear.
2. Add the `CrossIndieBanner` component (namespace `CrossIndie`) to it.
3. Configure in the Inspector or from code.

Public fields: `apiBase` (string), `appId` (string), `category` (string: game | web_tool | saas | mobile_app), `autoLoad` (bool). Events: `onAdLoaded(string)`, `onAdFailed(string)`. Method: `LoadAd()`.

```csharp
using CrossIndie;

var banner = rawImage.gameObject.AddComponent<CrossIndieBanner>();
banner.autoLoad = false;
banner.apiBase = "https://api.crossindie.com";
banner.appId = "YOUR_APP_ID";
banner.category = "game";
banner.onAdFailed.AddListener(reason => Debug.LogWarning(reason));
banner.LoadAd();
```

## Pitfalls

- Default `apiBase` is `http://localhost:8000`. Set it to `https://api.crossindie.com`.
- The component needs a `RawImage` on the same GameObject and a Canvas with a GraphicRaycaster plus an EventSystem in the scene, or clicks will not register (it implements `IPointerClickHandler`).
- Set fields before `LoadAd()`; with `autoLoad` the ad is requested in `Start`.
- Impressions count only while `Application.isFocused` is true.
- Clicks use `Application.OpenURL`.
- WebGL builds need the backend to allow your page's origin (CORS).
