Cocos2dx Native Ads Integration
Native Ads are a component-based ad format that allow publisher to display the customized ads on the application, how layouts headlines and call to action button. By choosing colors, image size and fonts etc for your application, you are able to display natural, well matched advertisement that can give better user experience. Ad impressions, ad clicks tracking, processing Advertising SDK.
Support OS
- Android
 - iOS
 
Android Class and Interface
Android native ad delivery, use the following class.
- CCGNSNativeAdRequest : Class to Request Native Ad with asynchronous
 - CCGNSNativeAd : Class to provide information of Native Ad
 - CCGNSNativeAdRequestDelegate : Interface to receive loading event of Native Ad
 jp_co_geniee_sdk_ads_nativead_GNNativeAdActivityBridge: A class that mediates native ad's android callback
iOS Classes and Protocols
iOS native ad delivery, use the following class.
- CCGNSNativeAdRequest.cpp: a class to request Native Ad
 - CCGNSNativeAd.cpp: a class to provide information of Native Ad
 - CCGNSNativeAdRequestDelegate: A protocol to receive loading event of Native
 - CCGNSNativeAdReqIOS.mm: A class that mediates native ad's iOS callback
 
Initialize SDK
Initialize SDK with the global App.
- Initialize SDK with the global
(Ex:Initialization when Application is started.) 
GNSAdSDK::CCGNSNativeAdRequest::initialize("YOUR_ZONE_ID");
 2
Initialization of SDK when acquiring multiple
Initialize SDK with the global App.
- Initialize SDK with comma-separated parameters. (Ex:Initialization when Application is started.)
 
GNSAdSDK::CCGNSNativeAdRequest::initialize("YOUR_ZONE_ID,YOUR_SSP_ZONE_ID2");
 2
Set Up Native Ads
CCGNSNativeAd,CCGNSNativeAdRequestwill be imported.
#include "CCGNSNativeAd.h"
#include "CCGNSNativeAdRequest.h"
 2
3
- Implement the 
CCGNSNativeAdRequestDelegateinterface. 
class HelloWorld : public cocos2d::Scene, CCGNSNativeAdRequestDelegate {
}
 2
3
- Initialize an instance of 
CCGNSNativeAdRequest. 
- Initialization API
 
GNSAdSDK::CCGNSNativeAdRequest::initialize(const char* zoneId);
 2
- Examples of using initialization API
 
GNSAdSDK::CCGNSNativeAdRequest::initialize("YOUR_ZONE_ID");
 2
YOUR_ZONE_ID sets the management ID of the frame within Geniee.
- An example of using multiple zone IDs:
 
If you want to get multiple ads at once. Please input your zone IDs sepeparated by a commas ,
GNSAdSDK::CCGNSNativeAdRequest::initialize("1234567,8956240,1234643");
 2
- Set Implementation class of 
CCGNSNativeAdRequestDelegateinterface 
Native ad load event, you will be notified by the implementation class via the interface.
Set the implementation variables of CCGNSNativeAdRequestDelegate interface.
GNSAdSDK::CCGNSNativeAdRequest::setDelegate(this);
 2
- Load NativeAds
 
- When you start requesting a single Native Ad
 
GNSAdSDK::CCGNSNativeAdRequest::loadAds();
 2
- When you start requesting more than one Native Ad at once
 
GNSAdSDK::CCGNSNativeAdRequest::multiLoadAds();
 2
- Implement 
CCGNSNativeAdRequestDelegateinterface
Implement CallBack function ofCCGNSNativeAdRequestDelegateto receive the result of native ad loading event. 
virtual void onNativeAdsLoaded(std::vector<GNSAdSDK::CCGNSNativeAd*> nativeAds);
virtual void onNativeAdsFailedToLoad();
virtual bool onShouldStartInternalBrowserWithClick(const char* url);
 2
3
4
Received native ads CCGNSNativeAd is return by an array of nativeAds arguments.
Distribution processing of multiple native advertising, done in CCGNSNativeAd ofzoneID information.
The number of elements in the array nativeAds :
- one : Select one ZONE_ID when Initialize CCGNSNativeAdRequest
- Example for implement HelloworldScene.h:
 
#include "CCGNSNativeAd.h"
#include "CCGNSNativeAdRequest.h"
class HelloWorld : public cocos2d::Scene, CCGNSNativeAdRequestDelegate
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
    // CCGNSNativeAdRequestDelegate callback
    virtual void onNativeAdsLoaded(std::vector<GNSAdSDK::CCGNSNativeAd*> nativeAds);
    virtual void onNativeAdsFailedToLoad();
    virtual bool onShouldStartInternalBrowserWithClick(const char* url);
};
 2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Example for implement HelloworldScene.cpp:
 
#include "HelloWorldScene.h"
USING_NS_CC;
Scene* HelloWorld::createScene()
{
    return HelloWorld::create();
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    GNSAdSDK::CCGNSNativeAdRequest::initialize("YOUR_ZONE_ID");
    GNSAdSDK::CCGNSNativeAdRequest::setDelegate(this);
    GNSAdSDK::CCGNSNativeAdRequest::loadAds();
    return true;
}
void HelloWorld::onNativeAdsLoaded(std::vector<GNSAdSDK::CCGNSNativeAd*> nativeAds) {
    for (GNSAdSDK::CCGNSNativeAd* _nativeAd : nativeAds) {
        log("NativeAd zoneID=%s", _nativeAd->zoneID);
        log("NativeAd advertiser=%s", _nativeAd->advertiser);
        log("NativeAd title=%s", _nativeAd->title);
        log("NativeAd description=%s", _nativeAd->description);
        log("NativeAd cta=%s", _nativeAd->cta);
        log("NativeAd icon_aspectRatio=%f", _nativeAd->icon_aspectRatio);
        log("NativeAd icon_url=%s", _nativeAd->icon_url);
        log("NativeAd icon_height=%d", _nativeAd->icon_height);
        log("NativeAd icon_width=%d", _nativeAd->icon_width);
        log("NativeAd screenshots_aspectRatio=%f", _nativeAd->screenshots_aspectRatio);
        log("NativeAd screenshots_url=%s", _nativeAd->screenshots_url);
        log("NativeAd screenshots_height=%d", _nativeAd->screenshots_height);
        log("NativeAd screenshots_width=%d", _nativeAd->screenshots_width);
        log("NativeAd app_appName=%s", _nativeAd->app_appName);
        log("NativeAd app_appid=%s", _nativeAd->app_appid);
        log("NativeAd app_rating=%f", _nativeAd->app_rating);
        log("NativeAd storeURL=%s", _nativeAd->app_storeURL);
        log("NativeAd targetAge=%s", _nativeAd->app_targetAge);
        _nativeAd->onTrackingImpression();
        _nativeAd->onTrackingClick();
    }
    log("NativeAd load success.");
}
void HelloWorld::onNativeAdsFailedToLoad() {
    log("NativeAd load fatal.");
}
bool HelloWorld::onShouldStartInternalBrowserWithClick(const char* url) {
    log("NativeAd click=%s", url);
    label->setString("NativeAd should start internal browser with click");
    return false;
}
 2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Rendering Native Ad
You need to render Native Ad based on information of received data.
Type of information data, refer definition of
CCGNSNativeAdclassIf the information data (const char* type) is not set, it will be
""If the information data (int, double type) is not set, it will be
0Information Name Type Content of Information zoneID const char* ID for AdZone in Geniee advertiser const char* Name of client title const char* Title of feed advertisement description const char* description of advertisment cta const char* text for "call to action" icon_aspectRatio double Aspect ratio of icon image icon_url const char* URL of icon image icon_height int heigh of icon image icon_width int width of icon image screenshots_aspectRatio double aspect ratio of screenshot screenshots_url const char* URL of screenshot image screenshots_height int heigh of screenshot image screenshots_width int width of screenshot image app_appName const char* Name of App app_appid const char* App ID(iOS:number、Android:package) app_rating double Evaluation of App app_storeURL const char* URL of App store app_targetAge const char* Target age of App 
Native ad impressions report
- When the Native Ad is rendered, you can extract the ad impression report.
 - For impressions native ads that has been previously reported, can not be reported again.
 - You need to request Native Ad again to display new advertisement.
 
nativeAd->onTrackingImpression();
 2
Native ad click tracking
- When Native ad is clicked, it will lead to ad landing page in external browser.
 
nativeAd->onTrackingClick();
 2
Landing page screen transition control when it is clicked
Landing page of Ads starts on an external browser by default,
Implement CallBack function of CCGNSNativeAdRequestDelegate,
With URL of landing page it is possible to start in-app browser.
In addition, by the return value of function, to control the start-up of an external browser.
If it returns true, you will need to request AppSide landingURL.
- false : Start the false external browser.
 - true : Do not start the true external browser.
 
virtual bool onShouldStartInternalBrowserWithClick(const char* landingURL)
 2
bool HelloWorld::onShouldStartInternalBrowserWithClick(const char* landingURL) {
    return false;
}
 2
3
4
Re-acquisition of native advertising
To view the new ads, you will need to re-acquire Native advertising by one of two APIs as the following.
- When you start requesting a single Native Ad
 
GNSAdSDK::CCGNSNativeAdRequest::loadAds();
 2
- When you start requesting more than one Native Ad at once
 
GNSAdSDK::CCGNSNativeAdRequest::multiLoadAds();
 2