Menu

Initialization instructions

• Your App needs to formulate a "Privacy Policy", display the "Privacy Policy" when users launch the App for the first time, and obtain user consent. For the "Privacy Policy" formulated by the App, please refer to "Privacy Compliance Guide" please make sure that the user agrees to the App's "Privacy Policy" , and then initialize TopOn SDK.

  • Before using the SDK to load and display ads, you need to call the initSDK method;
    • If it involves the EU region or related user privacy agreement controls, you can Control data reporting permissions through setGDPRLevel.
    • Through the setDebugLog method, you can turn on debugging logs to facilitate locating problems encountered in SDK integration.
    • Appid, appkey and other parameters required by DK It can be obtained after creating an app through the developer backend.

1 Initializing SDK

1.1 Initializing related APIs Description

Class name: ATCocosSdk.h

Description: The following is the common API for Android & iOS

APIParameter descriptionFunction description
integrationChecking-Check whether the SDK correctly integrates the SDK of the advertising platform
initSDKconst char * appId, const char * appKeyInitialize SDK How to obtain App Key?
setDebugLogbool valueOpen debug mode for SDK to view more logs
setChannelconst char * channelConfigure the channel number information of the SDK
setSubChannelconst char * subChannelConfigure the sub-channel number information of the SDK
setCustomDatacocos2d::ValueMap customDataConfigure custom parameters, which can be used to customize traffic grouping. The keys reserved by TopOn custom rules can be viewed Documentation.
setPlacementCustomDatacocos2d::ValueMap customDataConfigure custom parameters for ad slot dimensions
getUserLocationATCocosUserLocationListener * listenerDetermine whether it is in the European Union
ATCocosSdk::USER_LOCATION_UNKNOWN:Unknown
ATCocosSdk::USER_LOCATION_IN_EU:In the European Union

ATCocosSdk::USER_LOCATION_OUT_OF_EU
:In a non-EU region
setGDPRLevelint levelPlease refer to iOS platform or Android platform For the EU region, set GDPR privacy level

ATCocosSdk::GDPR_PERSONALIZED
: Full personalization
ATCocosSdk::GDPR_NONPERSONALIZED: No device information collected, no personalization
ATCocosSdk::GDPR_UNKNOWN: Unknown
getGDPRLevel-Get GDPR Privacy Level
ATCocosSdk::GDPR_PERSONALIZED: Fully Personalized
ATCocosSdk::GDPR_NONPERSONALIZED : No device information collected, no personalization
ATCocosSdk::GDPR_UNKNOWN: Unknown
showGdprAuth-Show GDPR authorization Page

Required for iOS part API

APIParameter descriptionFunction description
getScreenScale-Get screen size

1.2 Initialization sample code

// Test phase opened, please remove when release
ATCocosSdk::setDebugLog(true);
ATCocosSdk::integrationChecking();

ATCocosSdk::setChannel("test_cocos_channel");
ATCocosSdk::setSubChannel("test_cocos_sub_channel");

//custom rule for app 
cocos2d::ValueMap customDict; 
customDict["custom_data_key"] = "custom_data_value"; 
ATCocosSdk::setCustomData(customDict);

 //custom rule for placmenet 
 cocos2d::ValueMap plcamentCustomDict; 
 plcamentCustomDict["placement_custom_data_key"] = "placement_custom_data_value"; 
 ATCocosSdk::setPlacementCustomData(placementId, plcamentCustomDict);

ATCocosSdk::initSDK(appId, appKey);

2 GDPR description

2.1 GDPR related API description

APIParameter descriptionFunction description
getUserLocationATCocosUserLocationListener * listenerDetermine whether it is in the EU region
ATCocosSdk::USER_LOCATION_UNKNOWN: Unknown
ATCocosSdk::USER_LOCATION_IN_EU: It is in the EU region
ATCocosSdk::USER_LOCATION_OUT_OF_EU: In a non-EU region
setGDPRLevelint levelFor the EU region, set the GDPR privacy level
ATCocosSdk::GDPR_PERSONALIZED: Fully personalized

ATCocosSdk::GDPR_NONPERSONALIZED:
No device information collected, no personalization

ATCocosSdk::GDPR_UNKNOWN:
Unknown
getGDPRLevel-Get GDPR privacy level
ATCocosSdk::GDPR_PERSONALIZED: Full personalization
ATCocosSdk::GDPR_NONPERSONALIZED: No device information collected , no personalization
ATCocosSdk::GDPR_UNKNOWN: Unknown
showGdprAuth-Display GDPR authorization page
isEUTraffic-Determine whether it is an EU country

2.2 GDPR call example

    //check is in EU
    ATCocosSdk::getUserLocation(this);

    CCLOG("DemoMainScene::isEUTraffic %s", ATCocosSdk::isEUTraffic()?"YES":"NO");

    int gdpr_level = ATCocosSdk::getGDPRLevel();
    CCLOG("DemoMainScene::getGDPRLevel %d", gdpr_level);
    if (gdpr_level == ATCocosSdk::GDPR_PERSONALIZED) {
        CCLOG("DemoMainScene Full personalization");
    } else if (gdpr_level == ATCocosSdk::GDPR_UNKNOWN && ATCocosSdk::isEUTraffic() == YES){
        CCLOG("DemoMainScene Unknown");
        ATCocosSdk::showGdprAuthWithListener(this); // Pop-up authorization
    } ;
//    ATCocosSdk::setGDPRLevel(0);


Last modified: 2025-05-30Powered by