# Using the Superwall Delegate

Receive Superwall lifecycle callbacks in Unity.

Implement `ISuperwallDelegate` when your game needs callbacks for paywall lifecycle events,
subscription changes, custom paywall actions, deep links, or SDK logs.

Set a Delegate [#set-a-delegate]

Attach a delegate `MonoBehaviour` after `Superwall.Configure(...)`.

```csharp C#
using System.Collections.Generic;
using UnityEngine;
using Superwall;

public sealed class SuperwallEvents : MonoBehaviour, ISuperwallDelegate
{
    private void Start()
    {
        Superwall.Shared.SetDelegate(this);
    }

    public void SubscriptionStatusDidChange(SubscriptionStatus from, SubscriptionStatus to)
    {
        Debug.Log($"Subscription: {from.Type} -> {to.Type}");
    }

    public void HandleSuperwallEvent(SuperwallEventInfo eventInfo)
    {
        Debug.Log($"Superwall event: {eventInfo.EventType}");
    }

    public void HandleCustomPaywallAction(string name)
    {
        Debug.Log($"Custom action: {name}");
    }

    public void WillPresentPaywall(PaywallInfo paywallInfo) { }
    public void DidPresentPaywall(PaywallInfo paywallInfo) { }
    public void WillDismissPaywall(PaywallInfo paywallInfo) { }
    public void DidDismissPaywall(PaywallInfo paywallInfo) { }

    public void PaywallWillOpenURL(string url)
    {
        Application.OpenURL(url);
    }

    public void PaywallWillOpenDeepLink(string url)
    {
        Application.OpenURL(url);
    }

    public void HandleLog(
        string level,
        string scope,
        string message,
        Dictionary<string, object> info,
        string error
    )
    {
        if (level == "error")
        {
            Debug.LogError($"[Superwall] {scope}: {message} {error}");
        }
    }

    public void WillRedeemLink() { }
    public void DidRedeemLink(RedemptionResult result) { }

    public void HandleSuperwallDeepLink(
        string fullURL,
        List<string> pathComponents,
        Dictionary<string, string> queryParameters
    ) { }

    public void CustomerInfoDidChange(CustomerInfo from, CustomerInfo to) { }
    public void UserAttributesDidChange(Dictionary<string, object> newAttributes) { }
}
```

Custom Paywall Actions [#custom-paywall-actions]

Use custom actions when a paywall button should trigger game-specific behavior instead of a
purchase, restore, or close action.

```csharp C#
public void HandleCustomPaywallAction(string name)
{
    if (name == "open_level_preview")
    {
        OpenLevelPreview();
    }
}
```

Removing the Delegate [#removing-the-delegate]

Set the delegate to `null` when the object should no longer receive callbacks.

```csharp C#
Superwall.Shared.SetDelegate(null);
```