实施自定义年龄门

如果发布者或中介实施自定义年龄门解决方案,他们可以使用以下 API 将年龄门标志传递给 Unity Ads SDK。如果 Unity 收到此标志,其内置年龄门将不会出现。

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.