Rewarded Video

Rewarded video ads are full-screen videos that appear inside your application.

1. Load the rewarded video

Navigate to the header file that you want the rewarded video to appear in (e.g. MyViewController.h/ViewController.swift) and add the following import statement at the top of the file:

Objective-C
Swift
#import <Tapdaq/Tapdaq.h>

@interface MyViewController : UIViewController <TapdaqDelegate, TDAdRequestDelegate>

The above code imports Tapdaq to the class, and declares that we will conform to the TapdaqDelegate protocol.

Please note that you only need to provide import statement once per header file.

Next, add the following command to the implementation file (e.g. MyViewController.m/ViewController.swift):

Objective-C
Swift
- (void)viewDidLoad {
    [super viewDidLoad];
    [[Tapdaq sharedSession] setDelegate:self];
}

Once this is done, the Tapdaq delegate method -didLoadConfig becomes available, implement it like so:

Objective-C
Swift
- (void)didLoadConfig {
    [[Tapdaq sharedSession] loadRewardedVideoForPlacementTag:@"my_rewarded_tag" delegate:self];
}

This delegate method is invoked when the Tapdaq SDK has finished loading it's config, and is ready to begin loading ads.

Delegate parameter must conform to TDAdRequestDelegate.

Ads should only be requested once the Tapdaq delegate method -didLoadConfig has been called. This ensures Tapdaq is initialised and ready to begin loading ads. Requesting ads prior to Tapdaq initialising will result in failed ad requests

2. Display the rewarded video

We then need to display the rewarded ad to the user when they tap a button. Let's say you linked a -tappedReward: method to a UIButton:

Objective-C
Swift
- (IBAction)tappedReward:(id)sender {
    BOOL isReady = [[Tapdaq sharedSession] isRewardedVideoReadyForPlacementTag:@"my_rewarded_tag"];

    if (isReady) {
        [[Tapdaq sharedSession] showRewardedVideoForPlacementTag:@"my_rewarded_tag"];
    } else {
        // do something else
    }
}

This code checks to ensure there is a rewarded video ready to display before displaying it.

If you want to check a rewarded video is loaded before displaying the button a user would tap to see the reward, implement the following:

Objective-C
Swift
- (void)didLoadAdRequest:(TDAdRequest *)adRequest {
    if ([adRequest.placement.tag isEqualToString:@"my_rewarded_tag"]) {
        // Rewarded video is loaded, enable your rewarded video button, for example:
        [self.rewardedVideoButton setHidden:NO];
    }
}

For a full list of rewarded video delegate methods we support, see our Callbacks page.

3. Load another rewarded video on close

If you wish to load another rewarded video after you have shown one, implement one of the following options:

A. Auto Reload all Ads

To auto reload all ads using the same placement tag, set the global config before initializing, like so:

Objective-C
Swift
TDProperties *properties = [[TDProperties alloc] init];
[properties setAutoReloadAds:YES];

B. Implement the didCloseRewardedVideo Delegate with the placement tag you'd like to reload

When loading a rewarded video ad the delegate specified in the loadRewardedVideo can conform to TDDisplayableAdRequestDelegate which will allow it to handle didCloseAdRequest:.

Objective-C
Swift
- (void)didCloseAdRequest:(TDAdRequest *)adRequest {
    [[Tapdaq sharedSession] loadRewardedVideoForPlacementTag:placementTag delegate:self];
}

4. Reward the user

Finally, we want to reward the user for watching the video, implement the following delegate method to obtain the reward.

When loading a rewarded video ad the delegate specified in the loadRewardedVideo can conform to TDRewardedVideoAdRequestDelegate which will allow it to handle adRequest:didValidateReward:.

Note: TDReward.eventId is a unique identifier for every reward given to a user.

Objective-C
Swift
- (void)adRequest:(TDAdRequest *)adRequest didValidateReward:(TDReward *)reward {
    NSLog(@"The user received a reward! Name: %@, Amount: %d with tag: %@ eventId: %@ payload: %@", reward.name, reward.value, reward.tag, reward.eventId, reward.customJson);
}

Build and run your application to test the advert displays correctly.

Note: We strongly advise against trying to show a rewarded video ad on application launch.

In case the ad network did not validate reward adRequest:didFailToValidateReward: callback is called. TDReward object is also passed here so the user can be awarded regardless of whether reward was validated by the network.

Objective-C
Swift
- (void)adRequest:(TDAdRequest *)adRequest didFailToValidateReward:(TDReward *)reward {
NSLog(@"The reward was not validated! Name: %@, Amount: %d with tag: %@ eventId: %@ payload: %@", reward.name, reward.value, reward.tag, reward.eventId, reward.customJson);
}

Server Side Callbacks

Tapdaq SDK triggers server-side callbacks when a reward is provided, along with the client side didVerify callback.

Reward Id

The Reward Id is used for server-side callbacks, you can also retrieve it based on placement tags in the SDK like so:

Objective-C
Swift
[[Tapdaq sharedSession] rewardIdForPlacementTag:@"YOUR_PLACEMENT_TAG"];

Rewarded Video User Id

For server side callbacks, a Hashed User Id can be passed into the -showRewardedVideoForPlacementTag:hashedUserId: method, this will then be added to our server side callback to identify users.

The String should be hashed before passed to Tapdaq SDK

Objective-C
Swift
[[Tapdaq sharedSession] showRewardedVideoForPlacementTag:@"YOUR_PLACEMENT_TAG" hashedUserId:@"HASHED_USER_ID"];

Need help?

If you are having any problems integrating, feel free to contact us on [email protected] and we will be more than happy to help.

What's next?

Now that you have successfully integrated a rewarded video into your app, what would you like to do next?