Implementing custom age gates

If a publisher or mediator implements a custom age gate solution, they can use the following API to pass an age gate flag to the Unity Ads SDK. If Unity receives this flag, its built-in age gate will not appear.

Unity (C#)

// If the user is over the specified age limit:
MetaData ageGateMetaData = new MetaData("privacy");
ageGateMetaData.Set("useroveragelimit", "true");
Advertisement.SetMetaData(ageGateMetaData);
 
// If the user is under the specified age limit:
MetaData ageGateMetaData = new MetaData("privacy");
gdprMetaData.Set("useroveragelimit", "false");
Advertisement.SetMetaData(ageGateMetaData);

Note: You must commit the changes to the MetaData object for each value before trying to set another value. The second parameter is an object (a string in this example). Using a boolean value will result in an error.

iOS (Objective-C)

// If the user is over the specified age limit:
				UADSMetaData *ageGateMetaData = [[UADSMetaData alloc] init];
				[ageGateMetaData set:@"privacy.useroveragelimit" value:@YES];
				[ageGateMetaData commit];
				 
				// If the user is under the specified age limit:
				UADSMetaData *ageGateMetaData = [[UADSMetaData alloc] init];
				[ageGateMetaData set:@"privacy.useroveragelimit" value:@NO];
			[ageGateMetaData commit];

Note: You must commit the changes to the MetaData object for each value before trying to set another value.

Android (Java)

// If the user is over the specified age limit:
MetaData ageGateMetaData = new MetaData(this);
ageGateMetaData.set("privacy.useroveragelimit", true);
ageGateMetaData.commit();
 
// If the user is under the specified age limit:
MetaData ageGateMetaData = new MetaData(this);
ageGateMetaData.set("privacy.useroveragelimit", false);
ageGateMetaData.commit();

Note: You must commit the changes to the MetaData object for each value before trying to set another value.