{"_id":"594c59418c4f14001b973f40","project":"55de06fa57f7b20d0097636b","version":{"_id":"55de06fa57f7b20d0097636e","project":"55de06fa57f7b20d0097636b","__v":14,"createdAt":"2015-08-26T18:35:38.642Z","releaseDate":"2015-08-26T18:35:38.642Z","categories":["55de06fb57f7b20d0097636f","55f1962e3936d52d00fb3c8f","55f1970339e3e8190068b2b8","55f1970d229b772300779a1f","55f1971cfd98c42300acc605","55f1d5c7fd98c42300acc69f","563cbfe4260dde0d00c5e9d4","5644cf437f1fff210078e690","57dc1bbd3ed3450e00dc9ea7","58a600a2243dd30f00fd8773","58ed1bdc068f780f00f64602","58f13b3a4f0ee50f00e24e81","58f173f792f9020f009cad16","591b42f8e633fd0f00077c5a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"55f1962e3936d52d00fb3c8f","version":"55de06fa57f7b20d0097636e","__v":15,"pages":["55f196903936d52d00fb3c95","55f19c267dccfc0d00986b44","55f19da95fe76419007dc732","55f19ea639e3e8190068b2cc","55f19f7c7dccfc0d00986b4b","55f19fff3936d52d00fb3ca1","55f1a06d39e3e8190068b2d2","55f1a0925fe76419007dc737","55f1a0cb3936d52d00fb3cab","55f1b2be7dccfc0d00986b72","55f1b7d139e3e8190068b300","55f1b7fb229b772300779a4a","55f1be1efd98c42300acc64f","560956518aedf50d0004d0e2","565380daf77ca023004e5321"],"project":"55de06fa57f7b20d0097636b","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-10T14:39:42.948Z","from_sync":false,"order":1,"slug":"ios-sdk","title":"iOS SDK"},"user":"55de06e19db51a0d0064947d","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-06-22T23:56:49.483Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":12,"body":"[block:api-header]\n{\n  \"title\": \"Introduction\"\n}\n[/block]\nOne of the benefits of working with PushSpring's SDK is that you can easily send demographic (Age, Gender, Household Income) and other data to the Ad Networks you work with to monetize your apps.  By putting our SDK into your app, you can make a call to PushSpring to get data on the current device running your app, and then pass any relevant results to ad networks' SDKs and tags used in your app.  \n\nPassing these kinds of demographic parameters along with your calls to Ad Networks generally increases both fill rate (the percentage of time they return an ad for you) as well as CPM they pay, since it makes your app more valuable to ad network campaigns targeting those specific demographic segments.\n[block:api-header]\n{\n  \"title\": \"Using PushSpring Demographic Data with Ad Network SDKs\"\n}\n[/block]\nYou can use the `[[PushSpring sharedPushSpring] getCustomerInsights]` call to get the set of Demographic segments (Age, Gender, and Household Income) calculated by PushSpring for the current device.  Then, you can call into your ad network's SDK to provide that data.  Most network SDKs have a mechanism for you to set this data for the current user, and some require you to add it to every ad placement during initialization.\n\nWe have provided a wrapper class that does much of this work for you.  In your appDelegate after initializing the PushSpring SDK add the following code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::include \\\"AdParameterConfig.h\\\"\\n...\\n[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{}];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nA completion block is provided in case your ad sdk needs the parameters as part of its initialization. As an illustration, here is code that works with the AdColony SDK to transmit metadata about the current user via their AdColonyUserMetadata class:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\\n  [AdColony configureWithAppID:@\\\"<appId>\\\"\\n   zoneIDs:@[@\\\"<zoneId>\\\"]\\n   options: [[AdParameterConfig sharedAdParameterConfig] getAdColonyAppOptions]\\n   completion:^(NSArray<AdColonyZone*>* zones) {}\\n  ];\\n}];\\n\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"AdParameterConfig class\"\n}\n[/block]\nBelow is the .h file for the sample `AdParameterConfig` class.  You can copy this class into your app directly and then uncomment the references to the particular ad networks you are working with.  You can also use the `medianAge`, `medianIncome`, and `gender` properties with any ad network not included in the sample set below. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n//  AdParameterConfig.h\\n//  Copyright © 2017 PushSpring, Inc. All rights reserved.\\n//\\n\\n#import <Foundation/Foundation.h>\\n\\n// Uncomment the imports associated with the SDKs you have integrated in your app\\n//#import <AdColony/AdColony.h>\\n//@import GoogleMobileAds;\\n//#import <AmazonAd/AmazonAdOptions.h>\\n//#import <MMAdSDK/MMAdSDK.h>\\n\\n\\n@interface AdParameterConfig : NSObject\\n    + (AdParameterConfig *) sharedAdParameterConfig;\\n    - (void) getPSDataForDevice:(void (^)(void))completionHandler;\\n    - (NSString *) getMoPubKeywords;\\n    - (NSMutableArray *) getAerservKeywords;\\n// If you are working with any of the following, uncomment here\\n//    - (AdColonyAppOptions *) getAdColonyAppOptions;\\n//    - (void) setAdMobRequestTargeting:(GADRequest *)request;\\n//    - (AmazonAdOptions *) getAmazonAdOptions;\\n//    - (MMUserSettings *) getMillenialMediaUserSettings;\\n    @property (readonly,strong, nonatomic) NSNumber *medianAge;\\n    @property (readonly, strong, nonatomic) NSNumber *medianIncome;\\n    @property (readonly,strong, nonatomic) NSString *gender;\\n@end\\n\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\nAnd here is the corresponding Objective-C source for the class.  Again, uncomment the references to the particular ad networks you are working with:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n//  AdParameterConfig.m\\n//  Copyright © 2017 PushSpring, Inc. All rights reserved.\\n//\\n#import \\\"PushSpring.h\\\"\\n#import \\\"AdParameterConfig.h\\\"\\n\\n// Uncomment any of the below you are working with in this app\\n//#import <AdColony/AdColony.h>\\n//@import GoogleMobileAds;\\n//#import <AmazonAd/AmazonAdOptions.h>\\n//#import <MMAdSDK/MMAdSDK.h>\\n\\n\\n\\n@interface AdParameterConfig ()\\n    @property (strong, nonatomic) NSNumber *medianAge;\\n    @property (strong, nonatomic) NSNumber *medianIncome;\\n    @property (strong, nonatomic) NSString *gender;\\n    @property (strong, nonatomic) NSString *moPubKeywords;\\n    @property (strong, nonatomic) NSMutableArray *aerservKeywords;\\n@end\\n\\n@implementation AdParameterConfig\\n\\n+ (instancetype) sharedAdParameterConfig\\n    {\\n        static dispatch_once_t pred;\\n        static id sharedInstance = nil;\\n        dispatch_once(&pred, ^{\\n            sharedInstance = [[self alloc] init];\\n        });\\n        return sharedInstance;\\n    }\\n    \\n- (instancetype) init\\n    {\\n        self = [super init];\\n        if (self != nil)\\n        {\\n            _medianAge = nil;\\n            _gender = nil;\\n            _medianIncome = nil;\\n            _moPubKeywords = nil;\\n            _aerservKeywords = nil;\\n        }\\n        \\n        return self;\\n    }\\n\\n    \\n- (void) getPSDataForDevice:(void (^)(void))completionHandler\\n{\\n    [[PushSpring sharedPushSpring] getCustomerInsights:^(NSDictionary *calculatedAttributes) {\\n        if(calculatedAttributes!=nil && calculatedAttributes[@\\\"responses\\\"]!=nil) {\\n            if(calculatedAttributes[@\\\"responses\\\"][@\\\"medianAge\\\"]!=nil) {\\n                self.medianAge = @([calculatedAttributes[@\\\"responses\\\"][@\\\"medianAge\\\"] intValue]);\\n            }\\n            \\n            if(calculatedAttributes[@\\\"responses\\\"][@\\\"medianIncome\\\"]!=nil) {\\n                self.medianIncome = @([calculatedAttributes[@\\\"responses\\\"][@\\\"medianIncome\\\"] intValue]);\\n            }\\n            \\n            if(calculatedAttributes[@\\\"responses\\\"][@\\\"gender\\\"]!=nil) {\\n                self.gender = calculatedAttributes[@\\\"responses\\\"][@\\\"gender\\\"];\\n            }\\n        }\\n\\n        completionHandler();\\n    }];\\n}\\n    \\n    \\n// Uncommoent if you are working with AdColony\\n//- (AdColonyAppOptions *) getAdColonyAppOptions\\n//{\\n//    AdColonyAppOptions *options = [[AdColonyAppOptions alloc] init];\\n//    AdColonyUserMetadata *metaData = [[AdColonyUserMetadata alloc] init];\\n//    options.userMetadata = metaData;\\n//    \\n//    if(self.medianAge != nil) {\\n//        metaData.userAge = [self.medianAge intValue];\\n//    }\\n//    \\n//    if(self.medianIncome != nil) {\\n//        metaData.userHouseholdIncome = self.medianIncome;\\n//    }\\n//    \\n//    if(self.gender != nil) {\\n//        if([self.gender isEqualToString:@\\\"M\\\"]) {\\n//            metaData.userGender = ADCUserMale;\\n//        }\\n//        else if([self.gender isEqualToString:@\\\"F\\\"]) {\\n//            metaData.userGender = ADCUserFemale;\\n//        }\\n//    }\\n//\\n//    return options;\\n//}\\n    \\n- (NSString *) getMoPubKeywords\\n{\\n    if(self.moPubKeywords==nil) {\\n        NSMutableArray *keywords = [[NSMutableArray alloc] init];\\n        if(self.medianAge!=nil) {\\n            [keywords addObject:[NSString stringWithFormat:@\\\"m_age:%i\\\", [self.medianAge intValue]]];\\n        }\\n        \\n        if(self.gender!=nil) {\\n            [keywords addObject: [NSString stringWithFormat:@\\\"m_gender:%@\\\", [self.gender lowercaseString]]];\\n        }\\n        \\n        self.moPubKeywords = [keywords componentsJoinedByString:@\\\",\\\"];\\n    }\\n    \\n    return self.moPubKeywords;\\n}\\n    \\n- (NSMutableArray *) getAerservKeywords\\n{\\n    if(self.aerservKeywords==nil) {\\n        self.aerservKeywords = [[NSMutableArray alloc] init];\\n        \\n        if(self.gender!=nil) {\\n            if([self.gender isEqualToString:@\\\"M\\\"]) {\\n                [self.aerservKeywords addObject:@\\\"men\\\"];\\n            }\\n            else if([self.gender isEqualToString:@\\\"F\\\"]) {\\n                [self.aerservKeywords addObject:@\\\"women\\\"];\\n            }\\n        }\\n    }\\n    \\n    return [self.aerservKeywords copy];\\n}\\n    \\n// Uncomment if you are working with AdMob or Doubleclick\\n//- (void) setAdMobRequestTargeting:(GADRequest *)request\\n//{\\n//    if(self.gender!=nil) {\\n//        if([self.gender isEqualToString:@\\\"M\\\"]) {\\n//            request.gender = kGADGenderMale;\\n//        }\\n//        else if([self.gender isEqualToString:@\\\"F\\\"]) {\\n//            request.gender = kGADGenderFemale;\\n//        }\\n//    }\\n//    \\n//    if(self.medianAge!=nil) {\\n//        NSInteger thisYear = [[[NSCalendar currentCalendar]\\n//                         components:NSYearCalendarUnit fromDate:[NSDate date]]\\n//                        year];\\n//        NSDateComponents *components = [[NSDateComponents alloc] init];\\n//        components.year = thisYear - [self.medianAge intValue];\\n//        request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components];\\n//    }\\n//}\\n\\n// Uncomment if you are working with Amazon ads\\n// https://developer.amazon.com/blogs/appstore/post/Tx3K3WIJ2TB0JB0/ad-targeting-options-with-amazon-mobile-ads\\n//- (AmazonAdOptions *) getAmazonAdOptions\\n//{\\n//    AmazonAdOptions *options = [AmazonAdOptions options];\\n//    if(self.gender!=nil) {\\n//        if([self.gender isEqualToString:@\\\"M\\\"]) {\\n//           [options setAdvancedOption:@\\\"MALE\\\" forKey:@\\\"UserGender\\\"];\\n//        }\\n//        else if([self.gender isEqualToString:@\\\"F\\\"]) {\\n//            [options setAdvancedOption:@\\\"FEMALE\\\" forKey:@\\\"UserGender\\\"];\\n//        }\\n//    }\\n//\\n//    if(self.medianAge!=nil) {\\n//        [options setAdvancedOption:[self.medianAge stringValue] forKey:@\\\"Age\\\"];\\n//    }\\n//    \\n//    return options;\\n//}\\n\\n// Uncomment if working with AOL One Mobile / MillennialMedia\\n//- (MMUserSettings *) getMillenialMediaUserSettings\\n//{\\n//    MMUserSettings* userSettings = [[MMUserSettings alloc] init];\\n//  \\n//    if(self.medianAge != nil) {\\n//        userSettings.age = self.medianAge;\\n//    }\\n//    \\n//    if(self.medianIncome != nil) {\\n//        userSettings.income = self.medianIncome;\\n//    }\\n//    \\n//    if(self.gender != nil) {\\n//        if([self.gender isEqualToString:@\\\"M\\\"]) {\\n//            userSettings.gender = MMGenderMale;\\n//        }\\n//        else if([self.gender isEqualToString:@\\\"F\\\"]) {\\n//            userSettings.gender = MMGenderFemale;\\n//        }\\n//    }\\n//    \\n//    return userSettings;\\n//}\\n\\n@end\\n\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Sample Ad Network Configurations\"\n}\n[/block]\nTo help developers integrate parameter passing into a variety of different Ad Network SDKs, below you will find sample code which takes the response from the `[[PushSpring sharedPushSpring] getCustomerInsights]` call and configures a variety of different Ad Network SDKs to use the demographic data returned.\n\nTo use this code, simply copy and paste it into an appropriate part of your app (somewhere during initialization) and uncomment the code associated with any networks you are working with.  If there is a particular ad network SDK you would like us to add an example for, please reach out to [support@pushspring.com](mailto:support@pushspring.com) or your assigned PushSpring account manager.  \n[block:api-header]\n{\n  \"title\": \"Ad Colony\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\\n  [AdColony configureWithAppID:@\\\"<appId>\\\"\\n   zoneIDs:@[@\\\"<zoneId>\\\"]\\n   options: [[AdParameterConfig sharedAdParameterConfig] getAdColonyAppOptions]\\n   completion:^(NSArray<AdColonyZone*>* zones) {}\\n  ];\\n}];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"MoPub\"\n}\n[/block]\nWe support age and gender for MoPub.\n\nMake sure you have followed the directions to add the AdParameterConfig setup call to your app delegate.  Once that is done you can grab moPub keywords like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"self.mpAdView.keywords = [[AdParameterConfig sharedAdParameterConfig] getMoPubKeywords];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Aerserv\"\n}\n[/block]\nAerServ supports Gender targeting parameters.\n\nMake sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done you can grab Aerserv keywords like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"asAdView.keyWords = [[AdParameterConfig sharedAdParameterConfig] getAerservKeywords];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"AdMob\"\n}\n[/block]\nAdMob supports Birth Year and Gender targeting parameters.\n\nMake sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done you can set the targeting on GADRequest like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"GADRequest *request = [GADRequest request];\\n[[AdParameterConfig sharedAdParameterConfig] setAdMobRequestTargeting:request];\\n[self.bannerView loadRequest:request];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Amazon Ads\"\n}\n[/block]\nAmazon supports age and gender targeting parameters for Amazon ads.\n\nMake sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done set the AmazonAdOptions like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"AmazonAdOptions *options = [[AdParameterConfig sharedAdParameterConfig] getAmazonAdOptions];\\n[amazonAdView loadAd:options];\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Millennial Media\"\n}\n[/block]\nMillennial Media supports age and gender targeting parameters.\n\nMake sure you have followed the directions to add the AdParameterConfig setup call to your app delegate.  In the completion handler set the MMUserSettings like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\\n  //\\n  // Millenial Media\\n  //\\n  MMAppSettings* appSettings = [[MMAppSettings alloc] init];\\n  appSettings.siteId = @\\\"<Your siteId>\\\";\\n  MMUserSettings* userSettings = [[AdParameterConfig sharedAdParameterConfig] getMillenialMediaUserSettings];\\n  [[MMSDK sharedInstance] initializeWithSettings:appSettings withUserSettings:userSettings];\\n}];\\n\",\n      \"language\": \"objectivec\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"passing-parameters-to-ad-networks","type":"basic","title":"iOS - Passing Parameters to Ad Networks"}

iOS - Passing Parameters to Ad Networks


[block:api-header] { "title": "Introduction" } [/block] One of the benefits of working with PushSpring's SDK is that you can easily send demographic (Age, Gender, Household Income) and other data to the Ad Networks you work with to monetize your apps. By putting our SDK into your app, you can make a call to PushSpring to get data on the current device running your app, and then pass any relevant results to ad networks' SDKs and tags used in your app. Passing these kinds of demographic parameters along with your calls to Ad Networks generally increases both fill rate (the percentage of time they return an ad for you) as well as CPM they pay, since it makes your app more valuable to ad network campaigns targeting those specific demographic segments. [block:api-header] { "title": "Using PushSpring Demographic Data with Ad Network SDKs" } [/block] You can use the `[[PushSpring sharedPushSpring] getCustomerInsights]` call to get the set of Demographic segments (Age, Gender, and Household Income) calculated by PushSpring for the current device. Then, you can call into your ad network's SDK to provide that data. Most network SDKs have a mechanism for you to set this data for the current user, and some require you to add it to every ad placement during initialization. We have provided a wrapper class that does much of this work for you. In your appDelegate after initializing the PushSpring SDK add the following code: [block:code] { "codes": [ { "code": "@include \"AdParameterConfig.h\"\n...\n[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{}];", "language": "objectivec" } ] } [/block] A completion block is provided in case your ad sdk needs the parameters as part of its initialization. As an illustration, here is code that works with the AdColony SDK to transmit metadata about the current user via their AdColonyUserMetadata class: [block:code] { "codes": [ { "code": "[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\n [AdColony configureWithAppID:@\"<appId>\"\n zoneIDs:@[@\"<zoneId>\"]\n options: [[AdParameterConfig sharedAdParameterConfig] getAdColonyAppOptions]\n completion:^(NSArray<AdColonyZone*>* zones) {}\n ];\n}];\n", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "AdParameterConfig class" } [/block] Below is the .h file for the sample `AdParameterConfig` class. You can copy this class into your app directly and then uncomment the references to the particular ad networks you are working with. You can also use the `medianAge`, `medianIncome`, and `gender` properties with any ad network not included in the sample set below. [block:code] { "codes": [ { "code": "//\n// AdParameterConfig.h\n// Copyright © 2017 PushSpring, Inc. All rights reserved.\n//\n\n#import <Foundation/Foundation.h>\n\n// Uncomment the imports associated with the SDKs you have integrated in your app\n//#import <AdColony/AdColony.h>\n//@import GoogleMobileAds;\n//#import <AmazonAd/AmazonAdOptions.h>\n//#import <MMAdSDK/MMAdSDK.h>\n\n\n@interface AdParameterConfig : NSObject\n + (AdParameterConfig *) sharedAdParameterConfig;\n - (void) getPSDataForDevice:(void (^)(void))completionHandler;\n - (NSString *) getMoPubKeywords;\n - (NSMutableArray *) getAerservKeywords;\n// If you are working with any of the following, uncomment here\n// - (AdColonyAppOptions *) getAdColonyAppOptions;\n// - (void) setAdMobRequestTargeting:(GADRequest *)request;\n// - (AmazonAdOptions *) getAmazonAdOptions;\n// - (MMUserSettings *) getMillenialMediaUserSettings;\n @property (readonly,strong, nonatomic) NSNumber *medianAge;\n @property (readonly, strong, nonatomic) NSNumber *medianIncome;\n @property (readonly,strong, nonatomic) NSString *gender;\n@end\n", "language": "objectivec" } ] } [/block] And here is the corresponding Objective-C source for the class. Again, uncomment the references to the particular ad networks you are working with: [block:code] { "codes": [ { "code": "//\n// AdParameterConfig.m\n// Copyright © 2017 PushSpring, Inc. All rights reserved.\n//\n#import \"PushSpring.h\"\n#import \"AdParameterConfig.h\"\n\n// Uncomment any of the below you are working with in this app\n//#import <AdColony/AdColony.h>\n//@import GoogleMobileAds;\n//#import <AmazonAd/AmazonAdOptions.h>\n//#import <MMAdSDK/MMAdSDK.h>\n\n\n\n@interface AdParameterConfig ()\n @property (strong, nonatomic) NSNumber *medianAge;\n @property (strong, nonatomic) NSNumber *medianIncome;\n @property (strong, nonatomic) NSString *gender;\n @property (strong, nonatomic) NSString *moPubKeywords;\n @property (strong, nonatomic) NSMutableArray *aerservKeywords;\n@end\n\n@implementation AdParameterConfig\n\n+ (instancetype) sharedAdParameterConfig\n {\n static dispatch_once_t pred;\n static id sharedInstance = nil;\n dispatch_once(&pred, ^{\n sharedInstance = [[self alloc] init];\n });\n return sharedInstance;\n }\n \n- (instancetype) init\n {\n self = [super init];\n if (self != nil)\n {\n _medianAge = nil;\n _gender = nil;\n _medianIncome = nil;\n _moPubKeywords = nil;\n _aerservKeywords = nil;\n }\n \n return self;\n }\n\n \n- (void) getPSDataForDevice:(void (^)(void))completionHandler\n{\n [[PushSpring sharedPushSpring] getCustomerInsights:^(NSDictionary *calculatedAttributes) {\n if(calculatedAttributes!=nil && calculatedAttributes[@\"responses\"]!=nil) {\n if(calculatedAttributes[@\"responses\"][@\"medianAge\"]!=nil) {\n self.medianAge = @([calculatedAttributes[@\"responses\"][@\"medianAge\"] intValue]);\n }\n \n if(calculatedAttributes[@\"responses\"][@\"medianIncome\"]!=nil) {\n self.medianIncome = @([calculatedAttributes[@\"responses\"][@\"medianIncome\"] intValue]);\n }\n \n if(calculatedAttributes[@\"responses\"][@\"gender\"]!=nil) {\n self.gender = calculatedAttributes[@\"responses\"][@\"gender\"];\n }\n }\n\n completionHandler();\n }];\n}\n \n \n// Uncommoent if you are working with AdColony\n//- (AdColonyAppOptions *) getAdColonyAppOptions\n//{\n// AdColonyAppOptions *options = [[AdColonyAppOptions alloc] init];\n// AdColonyUserMetadata *metaData = [[AdColonyUserMetadata alloc] init];\n// options.userMetadata = metaData;\n// \n// if(self.medianAge != nil) {\n// metaData.userAge = [self.medianAge intValue];\n// }\n// \n// if(self.medianIncome != nil) {\n// metaData.userHouseholdIncome = self.medianIncome;\n// }\n// \n// if(self.gender != nil) {\n// if([self.gender isEqualToString:@\"M\"]) {\n// metaData.userGender = ADCUserMale;\n// }\n// else if([self.gender isEqualToString:@\"F\"]) {\n// metaData.userGender = ADCUserFemale;\n// }\n// }\n//\n// return options;\n//}\n \n- (NSString *) getMoPubKeywords\n{\n if(self.moPubKeywords==nil) {\n NSMutableArray *keywords = [[NSMutableArray alloc] init];\n if(self.medianAge!=nil) {\n [keywords addObject:[NSString stringWithFormat:@\"m_age:%i\", [self.medianAge intValue]]];\n }\n \n if(self.gender!=nil) {\n [keywords addObject: [NSString stringWithFormat:@\"m_gender:%@\", [self.gender lowercaseString]]];\n }\n \n self.moPubKeywords = [keywords componentsJoinedByString:@\",\"];\n }\n \n return self.moPubKeywords;\n}\n \n- (NSMutableArray *) getAerservKeywords\n{\n if(self.aerservKeywords==nil) {\n self.aerservKeywords = [[NSMutableArray alloc] init];\n \n if(self.gender!=nil) {\n if([self.gender isEqualToString:@\"M\"]) {\n [self.aerservKeywords addObject:@\"men\"];\n }\n else if([self.gender isEqualToString:@\"F\"]) {\n [self.aerservKeywords addObject:@\"women\"];\n }\n }\n }\n \n return [self.aerservKeywords copy];\n}\n \n// Uncomment if you are working with AdMob or Doubleclick\n//- (void) setAdMobRequestTargeting:(GADRequest *)request\n//{\n// if(self.gender!=nil) {\n// if([self.gender isEqualToString:@\"M\"]) {\n// request.gender = kGADGenderMale;\n// }\n// else if([self.gender isEqualToString:@\"F\"]) {\n// request.gender = kGADGenderFemale;\n// }\n// }\n// \n// if(self.medianAge!=nil) {\n// NSInteger thisYear = [[[NSCalendar currentCalendar]\n// components:NSYearCalendarUnit fromDate:[NSDate date]]\n// year];\n// NSDateComponents *components = [[NSDateComponents alloc] init];\n// components.year = thisYear - [self.medianAge intValue];\n// request.birthday = [[NSCalendar currentCalendar] dateFromComponents:components];\n// }\n//}\n\n// Uncomment if you are working with Amazon ads\n// https://developer.amazon.com/blogs/appstore/post/Tx3K3WIJ2TB0JB0/ad-targeting-options-with-amazon-mobile-ads\n//- (AmazonAdOptions *) getAmazonAdOptions\n//{\n// AmazonAdOptions *options = [AmazonAdOptions options];\n// if(self.gender!=nil) {\n// if([self.gender isEqualToString:@\"M\"]) {\n// [options setAdvancedOption:@\"MALE\" forKey:@\"UserGender\"];\n// }\n// else if([self.gender isEqualToString:@\"F\"]) {\n// [options setAdvancedOption:@\"FEMALE\" forKey:@\"UserGender\"];\n// }\n// }\n//\n// if(self.medianAge!=nil) {\n// [options setAdvancedOption:[self.medianAge stringValue] forKey:@\"Age\"];\n// }\n// \n// return options;\n//}\n\n// Uncomment if working with AOL One Mobile / MillennialMedia\n//- (MMUserSettings *) getMillenialMediaUserSettings\n//{\n// MMUserSettings* userSettings = [[MMUserSettings alloc] init];\n// \n// if(self.medianAge != nil) {\n// userSettings.age = self.medianAge;\n// }\n// \n// if(self.medianIncome != nil) {\n// userSettings.income = self.medianIncome;\n// }\n// \n// if(self.gender != nil) {\n// if([self.gender isEqualToString:@\"M\"]) {\n// userSettings.gender = MMGenderMale;\n// }\n// else if([self.gender isEqualToString:@\"F\"]) {\n// userSettings.gender = MMGenderFemale;\n// }\n// }\n// \n// return userSettings;\n//}\n\n@end\n", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "Sample Ad Network Configurations" } [/block] To help developers integrate parameter passing into a variety of different Ad Network SDKs, below you will find sample code which takes the response from the `[[PushSpring sharedPushSpring] getCustomerInsights]` call and configures a variety of different Ad Network SDKs to use the demographic data returned. To use this code, simply copy and paste it into an appropriate part of your app (somewhere during initialization) and uncomment the code associated with any networks you are working with. If there is a particular ad network SDK you would like us to add an example for, please reach out to [support@pushspring.com](mailto:support@pushspring.com) or your assigned PushSpring account manager. [block:api-header] { "title": "Ad Colony" } [/block] [block:code] { "codes": [ { "code": "[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\n [AdColony configureWithAppID:@\"<appId>\"\n zoneIDs:@[@\"<zoneId>\"]\n options: [[AdParameterConfig sharedAdParameterConfig] getAdColonyAppOptions]\n completion:^(NSArray<AdColonyZone*>* zones) {}\n ];\n}];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "MoPub" } [/block] We support age and gender for MoPub. Make sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done you can grab moPub keywords like this: [block:code] { "codes": [ { "code": "self.mpAdView.keywords = [[AdParameterConfig sharedAdParameterConfig] getMoPubKeywords];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "Aerserv" } [/block] AerServ supports Gender targeting parameters. Make sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done you can grab Aerserv keywords like this: [block:code] { "codes": [ { "code": "asAdView.keyWords = [[AdParameterConfig sharedAdParameterConfig] getAerservKeywords];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "AdMob" } [/block] AdMob supports Birth Year and Gender targeting parameters. Make sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done you can set the targeting on GADRequest like this: [block:code] { "codes": [ { "code": "GADRequest *request = [GADRequest request];\n[[AdParameterConfig sharedAdParameterConfig] setAdMobRequestTargeting:request];\n[self.bannerView loadRequest:request];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "Amazon Ads" } [/block] Amazon supports age and gender targeting parameters for Amazon ads. Make sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. Once that is done set the AmazonAdOptions like this: [block:code] { "codes": [ { "code": "AmazonAdOptions *options = [[AdParameterConfig sharedAdParameterConfig] getAmazonAdOptions];\n[amazonAdView loadAd:options];", "language": "objectivec" } ] } [/block] [block:api-header] { "title": "Millennial Media" } [/block] Millennial Media supports age and gender targeting parameters. Make sure you have followed the directions to add the AdParameterConfig setup call to your app delegate. In the completion handler set the MMUserSettings like this: [block:code] { "codes": [ { "code": "[[AdParameterConfig sharedAdParameterConfig] getPSDataForDevice:^{\n //\n // Millenial Media\n //\n MMAppSettings* appSettings = [[MMAppSettings alloc] init];\n appSettings.siteId = @\"<Your siteId>\";\n MMUserSettings* userSettings = [[AdParameterConfig sharedAdParameterConfig] getMillenialMediaUserSettings];\n [[MMSDK sharedInstance] initializeWithSettings:appSettings withUserSettings:userSettings];\n}];\n", "language": "objectivec" } ] } [/block]