# CrossIndie Web SDK

Cross-promotion banner for websites, web tools and micro-SaaS. No dependencies, no build step, about 2 KB gzipped.

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

Use the hosted script (preferred):

```html
<script src="https://api.crossindie.com/embed.js" data-api-base="https://api.crossindie.com" async></script>
```

Or `npm install @crossindie/web` (package ships `embed.js` and TypeScript types; it exposes `window.CrossIndie`).

## Usage

### Declarative slots (recommended)

Any element with `data-ci-app-id` becomes one independent slot:

```html
<div data-ci-app-id="YOUR_APP_ID" data-ci-category="web_tool" data-ci-format="leaderboard"></div>
<div data-ci-app-id="YOUR_APP_ID" data-ci-category="web_tool" data-ci-format="rectangle"></div>
```

Attributes: `data-ci-app-id` (required), `data-ci-category`, `data-ci-format`, `data-ci-country` (e.g. "US"), `data-ci-close="false"` to hide the dismiss button, `data-ci-api-base` (overrides the script tag's `data-api-base`).

### Single slot from the script tag

```html
<div id="crossindie-banner"></div>
<script src="https://api.crossindie.com/embed.js" data-app-id="YOUR_APP_ID" data-category="web_tool" data-api-base="https://api.crossindie.com" async></script>
```

Script-tag attributes: `data-app-id`, `data-category`, `data-format`, `data-country`, `data-close`, `data-target` (element id, default `crossindie-banner`), `data-api-base`.

### Programmatic

```js
window.addEventListener("load", () => {
  CrossIndie.createBanner({
    el: "#banner",            // element, id or selector; default "crossindie-banner"
    appId: "YOUR_APP_ID",
    category: "web_tool",     // game | web_tool | saas | mobile_app (default "game")
    format: "rectangle",      // card | rectangle | leaderboard | mobile | text (default "card")
    apiBase: "https://api.crossindie.com",
    lang: "en",               // optional targeting
    country: "US",            // optional targeting
    video: true,              // set false to never request video
    close: true,              // small X; a dismissed slot earns nothing
    onError: (e) => console.warn(e),
  });
});
```

`createBanner` returns a Promise<boolean> (true if shown). `CrossIndie.initSlots(defaultApiBase)` re-scans the page for `data-ci-app-id` slots (useful after client-side routing).

Formats: card (320 px wide), rectangle (300x250), leaderboard (728x90), mobile (320x50), text (no image).

## Pitfalls

- `apiBase` is required for programmatic use and must be `https://api.crossindie.com`. Without `data-api-base` on the script tag, declarative slots have no backend.
- In SPAs (React, Next.js, Vue) load the script once, and call `CrossIndie.initSlots(apiBase)` after the slot elements mount. Do not render the slot element server-side with content inside it.
- Set **Allowed web domains** on the app in the dashboard so the app_id only works on your own hosts.
- Ad blockers may hide the slot. That is expected; nothing to fix.
- Do not hide the banner with CSS or cover it: impressions require continuous visibility.
- Conversion tracking (optional): clicks land on your URL with a `ci_ref` query parameter; POST `{ "ref": ci_ref }` to `https://api.crossindie.com/api/v1/ad/convert` once when the user converts.
