# Implementing custom AdNetwork

Create class that is inheritance of AdNetwork;

Implement abstact methods;

{% hint style="danger" %}
Every ad sdk should have callbacks for ad start / finish / fail and more.\
You need to override Init() method with base() call and subscribe to sdk events.

for ShowInterstitial and ShowRewarded make sure to save callback input into\ <mark style="color:red;">**\_onInterstitialHidden**</mark> and <mark style="color:red;">**\_onRewardedClosed**</mark>. It should be like this:

<pre class="language-csharp"><code class="lang-csharp">public override void ShowInterstitial(string placement, Action callback = null) {
    _onInterstitialHidden = callback; // remember, use on ad adk callbacks
    MaxSdk.ShowInterstitial(_appLovinSettings.AdInterstitialId);
}
<strong>public override void ShowRewarded(string placement, Action&#x3C;bool> callback = null) {
</strong>    _onRewardedClosed = callback; // remember, use on ad adk callbacks
    MaxSdk.ShowRewardedAd(_appLovinSettings.AdRewardedId);
}
// this is AppLovin implementation as example.
</code></pre>

\
Then invoke cached callbacks from ad sdk callbacks, as example:

```csharp
private void OnInterstitialHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {
    _manager.StartInterstitialCooldownAfter(AdType.Interstitial); // this is important to update cooldown for next interstitial
    LoadInterstitial();
    _onInterstitialHidden?.Invoke();
    _onInterstitialHidden = null;
}
```

\
\&#xNAN;**\_manager.StartInterstitialCooldownAfter(AdType.Interstitial or AdType.Rewarded);**\ <mark style="color:red;">**must**</mark> be called on success ad watch to update inter show cooldowns. \
Needs to be after rewarded and inter with correspoding AdType passed to manager.
{% endhint %}

Add your network implementation script to AdManager and reference it to ActiveNetwork field in AdManager.

You can see ready-made network implementations as examples from [](https://reddycat.gitbook.io/base-project-cube-doc/other/add-on-.unitypackage-archive/generic-ad-manager "mention") page.
