AI-промпт для интеграции Unity SDK — GameDevPartner

GameDevPartner SDK — AI Prompt

Скопируйте этот промпт в ChatGPT, Claude или другую нейросеть — она интегрирует SDK в ваш Unity-проект.

# GameDevPartner Unity SDK — Integration Guide for AI (v2.6.5)

You are integrating the GameDevPartner SDK into a Unity mobile game (Android/iOS).
The SDK tracks installs, in-app purchases, and ad impressions so the platform can attribute
revenue back to the influencer who brought the player.

## Package identity — AUTHORITATIVE, do NOT guess and do NOT ask the user to confirm

These values are exact. Use them directly — never stop to ask the developer to verify them
or to read package.json from the git repo; that is already done for you here:

- UPM package name (manifest.json key): `com.gamedevpartner.sdk`
- Git URL: `https://gitlab.com/nonstop1899/gamedevpartner-unity-sdk.git`
- C# namespace: `GameDevPartner.SDK`
- Main entry class: `GameDevPartnerSDK` (static; auto-initializes via [RuntimeInitializeOnLoadMethod])
- Config asset: `GameDevPartnerConfig` ScriptableObject in a Resources/ folder
- Minimum Unity: 2020.3
- Current version: 2.6.5

When wiring code, `using GameDevPartner.SDK;` and call `GameDevPartnerSDK.IdentifyPlayer(...)`,
`GameDevPartnerSDK.TrackPurchase(...)`, `GameDevPartnerSDK.TrackAdRevenue(...)`. Do not invent
other namespaces or class names.

## Platform architecture you must understand

- The SDK runs inside the game. It auto-identifies the player by device ID on first launch,
  reads install referrer, signs every request with HMAC-SHA256, and sends events to
  `gamedevpartner.ru`.
- Purchases are posted by the game code (one `TrackPurchase` call per purchase).
- Ad impressions are posted by the game code (one `TrackAdRevenue` call per impression).
  For networks that expose per-impression revenue in their callback, pass that value.
  For Unity Ads standard SDK (which does NOT expose revenue), pass revenue=0 — the platform
  pulls exact revenue nightly from Unity Monetization Stats API and distributes it across
  SDK-recorded impressions. The developer connects Reporting credentials in the dashboard.

## Installation

### Fresh install
Unity Package Manager → "+" → "Add package from git URL":
```
https://gitlab.com/nonstop1899/gamedevpartner-unity-sdk.git
```

### Updating from an earlier version — DO NOT just click "Update"
Unity's Package Manager often keeps a stale cached copy of git-based packages. After
"Update", the PackageCache folder may still contain the old commit hash, and none of
the fixes in the new version will be applied. Always full-reset:

1. Window → Package Manager → select GameDevPartner SDK → **Remove**
2. Close Unity
3. Manually delete `<ProjectRoot>/Library/PackageCache/com.gamedevpartner.sdk@*` (any folders
   starting with that name)
4. Reopen Unity and let it finish compiling
5. Window → Package Manager → "+" → "Add package from git URL" → paste the URL again → Add

### Requirements
- Unity 2020.3 or newer.
- No other Unity packages are required.
- Unity IAP is OPTIONAL. If it's in the project (package `com.unity.purchasing`), the SDK
  compiles an extra sub-assembly `GameDevPartner.SDK.IAP` that exposes the
  `GDPUnityIAP` helper class. If Unity IAP is NOT installed, that sub-assembly is skipped
  entirely via asmdef `defineConstraints` — no missing-reference errors, no cascade
  failures, `Window → GameDevPartner → Settings` menu still appears normally.

### Verify install succeeded
After Package Manager finishes importing:
- Console has zero errors from `Library\PackageCache\com.gamedevpartner.sdk@...`
- Menu `Window → GameDevPartner → Settings` exists
- Opening it shows the settings window with an `API Key` field

If `Window → GameDevPartner` does NOT appear, the runtime asmdef failed to compile.
Check the Console for the first SDK-related error (ignore `.meta` GUID warnings from
your own Assets — those are unrelated). Then redo the full-reset steps above.

## Setup (one-time)

1. Window → GameDevPartner → Settings
2. Paste the API Key from gamedevpartner.ru → Developer → Мои игры → the game's card → "API-ключ"
3. Region: `RU` (for Russian market) or `World`
4. Auto Identify Player: ON (recommended; uses device ID)
5. Debug Mode: ON while developing, OFF for production builds

## Namespaces

```csharp
using GameDevPartner.SDK;
// Main class: GameDevPartnerSDK
// DTOs: PurchaseEvent, PaymentSource
```

## What the SDK does automatically — don't re-implement

- Identifies the player (device ID) on first launch
- Reads Google Play / RuStore Install Referrer for attribution
- Signs requests (HMAC-SHA256 with ApiKey + timestamp)
- Queues purchases offline (up to 100 events), retries on reconnect

Never call `GameDevPartnerSDK.Init()` — auto-init via `[RuntimeInitializeOnLoadMethod]`.
Never call `IdentifyPlayer()` unless Auto Identify is OFF.

==================================================================
## Purchase tracking — mandatory
==================================================================

### Option A: Unity IAP (the one-line integration)

Replace `UnityPurchasing.Initialize(this, builder)` with the SDK wrapper:

```csharp
using GameDevPartner.SDK;
// before: UnityPurchasing.Initialize(this, builder);
GDPUnityIAP.Initialize(this, builder);
```

That's it. Every successful Google Play / App Store purchase is tracked automatically
with the correct `TransactionId`, `Amount`, `Currency`, and `ReceiptData`.

### Option B: Manual tracking (YooKassa, TBank, RuStore, Web, custom)

Call `TrackPurchase` exactly once per successful payment, inside the success callback:

```csharp
using GameDevPartner.SDK;

GameDevPartnerSDK.TrackPurchase(new PurchaseEvent {
    ProductId = "gem_pack_100",               // your product ID
    Amount = 99f,                              // gross price the player paid (before store commission)
    Currency = "RUB",                          // ISO 4217
    Source = PaymentSource.YooKassa,           // see table below
    TransactionId = paymentId,                 // unique ID from the payment system
    ReceiptData = receiptOrNull,               // optional, for server-side validation
});
```

### PaymentSource values (enum)

| Value | When to use |
|---|---|
| `PaymentSource.GooglePlay` | Google Play Billing (Unity IAP uses this automatically) |
| `PaymentSource.Apple` | Apple StoreKit (Unity IAP uses this automatically) |
| `PaymentSource.YooKassa` | YooKassa SDK |
| `PaymentSource.TBank` | TBank / Tinkoff payments |
| `PaymentSource.RuStore` | RuStore billing |
| `PaymentSource.Web` | Web checkout (Stripe, PayPal, etc.) |
| `PaymentSource.Other` | Anything else |

==================================================================
## Ad revenue tracking — mandatory if the game shows ads
==================================================================

Single universal method with POSITIONAL arguments (no `new AdRevenueEvent {}` class):

```csharp
GameDevPartnerSDK.TrackAdRevenue(
    double revenue,   // amount per impression; pass 0 for Unity Ads standard (see below)
    string currency,  // "USD" | "RUB" | ISO 4217
    string adType,    // "rewarded" | "interstitial" | "banner"
    string adNetwork, // string (not enum): "yandex_ads" | "unity_ads" | "admob" | "ironsource" | "applovin" | "other"
    string adUnitId   // optional, ad unit / placement ID
);
```

### adNetwork values — EXACT strings (not enums)

`"yandex_ads"`, `"unity_ads"`, `"admob"`, `"ironsource"`, `"applovin"`, `"other"`

### Two callback scenarios — pick the right one per ad network

#### Scenario 1: networks that expose revenue in the impression callback (ILAR)

AppLovin MAX, IronSource (LevelPlay), AdMob, Yandex Ads with mediation — pass the real
per-impression revenue:

```csharp
// Yandex Ads (mediation) — impression callback carries rawData JSON:
rewardedAd.OnAdImpression += (sender, data) => {
    var json = JsonUtility.FromJson<ImpressionJson>(data.rawData);
    GameDevPartnerSDK.TrackAdRevenue(json.revenue, json.currency, "rewarded", "yandex_ads", adUnitId);
};

// AppLovin MAX:
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += (id, info) =>
    GameDevPartnerSDK.TrackAdRevenue(info.Revenue, "USD", "rewarded", "applovin", id);

// IronSource (LevelPlay):
IronSourceEvents.onImpressionDataReadyEvent += (data) =>
    GameDevPartnerSDK.TrackAdRevenue(data.revenue ?? 0, "USD", data.adUnit, "ironsource");

// AdMob — value arrives in micros, divide by 1,000,000:
rewardedAd.OnAdPaid += (adValue) =>
    GameDevPartnerSDK.TrackAdRevenue(adValue.Value / 1000000.0, adValue.CurrencyCode, "rewarded", "admob", adUnitId);
```

#### Scenario 2: Unity Ads standard SDK (NOT LevelPlay)

The Unity Ads standard SDK does NOT expose per-impression revenue in any callback
(no `data.revenue`, no `ImpressionEventPublisher` — do not invent these).

Instead:

a) The developer connects Unity Ads in the GameDevPartner dashboard:
   ЛК → Мои игры → разверните карточку игры → секция «Рекламные сети» → Unity Ads
   Three fields:
   - Organization Core ID (Unity Dashboard → Organization Settings → Organization core ID)
   - Monetization Stats API Key (Unity Dashboard → Monetization → Setup → API Management
     → Monetization Stats API Access → Regenerate)
   - Game IDs (comma-separated Android+iOS project IDs from Unity Dashboard → Projects,
     e.g. `6077073,6077072`; WITHOUT this filter the API sums all games in the org)

b) The platform's nightly cron (01:15 MSK) pulls exact revenue in USD via Unity
   Monetization Stats API, converts to RUB via Central Bank rate, and distributes it
   across the SDK-recorded impressions for that day.

c) In the callback, pass revenue=0 — the call is only needed to LINK the impression to
   the specific player / influencer:

```csharp
public class AdController : MonoBehaviour, IUnityAdsShowListener {
    public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState state) {
        if (state == UnityAdsShowCompletionState.COMPLETED) {
            // revenue=0 is INTENTIONAL — exact $ arrives nightly from Monetization Stats API
            GameDevPartnerSDK.TrackAdRevenue(0, "USD", "rewarded", "unity_ads", placementId);
        }
    }
    // ... OnUnityAdsShowStart / OnUnityAdsShowFailure / OnUnityAdsShowClick — nothing to add
}
```

### iOS vs Android may use different networks

If Android uses Yandex with mediation and iOS uses Unity Ads standard (or any other
combination), add `TrackAdRevenue` in EACH network's callback with the correct `adNetwork`
string. The SDK itself determines the platform; you just pass the right network name.

==================================================================
## Gradle (Android only) — improves attribution accuracy
==================================================================

Add to `Plugins/Android/mainTemplate.gradle` (or `mainTemplate.gradle`):

```gradle
dependencies {
    implementation 'com.android.installreferrer:installreferrer:2.2'
}
```

Without this dependency, the SDK falls back to GAID / device fingerprint attribution —
still works, just less accurate.

==================================================================
## Hard NO-GO list
==================================================================

- Do NOT call `IdentifyPlayer()` if Auto Identify is ON (it runs automatically)
- Do NOT track the same purchase twice — SDK already deduplicates by `TransactionId`
- Do NOT ship with the test API key in production builds
- Do NOT include store commission in `Amount` — use the gross price the player paid
- Do NOT invent revenue values for Unity Ads standard — pass 0 and connect the dashboard
- Do NOT write `new AdRevenueEvent { ... }` — no such class exists; arguments are POSITIONAL
- Do NOT write `AdNetwork.Something` enum — `adNetwork` is a plain string from the list above
- Do NOT reference `ImpressionEventPublisher` / `data.revenue` for Unity Ads standard SDK —
  these do NOT exist in that SDK (they exist only in LevelPlay, which is separate)

==================================================================
## Integration checklist
==================================================================

- [ ] Unity Package Manager installs the SDK from the git URL without errors
- [ ] Window → GameDevPartner → Settings appears; API key saved
- [ ] Purchases tracked (either `GDPUnityIAP.Initialize` or manual `TrackPurchase`)
- [ ] Every ad impression callback calls `TrackAdRevenue` with correct `adNetwork` string
- [ ] Unity Ads standard: `revenue=0` passed AND dashboard has Core ID + Stats API Key + Game IDs
- [ ] Gradle `installreferrer:2.2` added for Android
- [ ] Test build: a test purchase and an ad impression appear in
      gamedevpartner.ru/developer/analytics within a minute
- [ ] Debug Mode turned OFF in the production build