{"_id":"594c9b72c804570021d220ab","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":"55f1970339e3e8190068b2b8","pages":["55f1a1e6229b772300779a34","55f1b11b39e3e8190068b2f1","55f1b59b39e3e8190068b2fc","55f1b6215fe76419007dc760","55f1b69539e3e8190068b2fe","55f1b90a5fe76419007dc763","55f1b93ffd98c42300acc643"],"project":"55de06fa57f7b20d0097636b","version":"55de06fa57f7b20d0097636e","__v":7,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-10T14:43:15.288Z","from_sync":false,"order":2,"slug":"android-sdk","title":"Android SDK"},"user":"55de06e19db51a0d0064947d","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-06-23T04:39:14.465Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":10,"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().getRealtimeCustomerInsights()` 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\nTo help you glue the PushSpring data returned from this call into the various Ad Network SDKs you might be using, below we provide the source for a Java class called `AdParameterConfig` that you can include in your apps.  This class is designed to be initialized right after you initialize the PushSpring SDK in your code, most likely in the \"main\" activity of your app at startup, with code like the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::Override\\nprotected void onCreate(Bundle savedInstanceState) {\\n\\t  super.onCreate(savedInstanceState);\\n\\t  setContentView(R.layout.activity_main);\\n\\t\\t\\n    PushSpring pushSpring = PushSpring.sharedPushSpring();\\n    pushSpring.onCreate(this, PS_API_KEY, googlePlayConnector);\\n    AdParameterConfig adParameterConfig = new AdParameterConfig();\\n             ...\\n}\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nThe `AdParameterConfig` class makes the necessary call to PushSpring to retrieve Gender, Age, and Household Income demographic data for the current device, and has methods you can use with various Ad Networks to configure this data into your ad calls. \n[block:api-header]\n{\n  \"title\": \"AdParameterConfig Class Source\"\n}\n[/block]\nThis class is meant as a sample that you can drop into an existing app and then modify as needed.\nTo use it, copy it into your source tree, change the package information, and then uncomment the methods that are designed to work with your existing ad monetization partners.  You can also use the generic methods `getAge()`, `getGender()`, and `getIncome()` and use that data to configure any other ad networks you need. \n\nMake sure you initialize this class soon after initializing the PushSpring SDK.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"package com.pushspring.adnetworksample;\\n\\n// Uncomment any of the below you have embedded in your app\\n//import com.adcolony.sdk.AdColonyUserMetadata;\\n//import com.amazon.device.ads.AdTargetingOptions;\\n//import com.millennialmedia.UserData;\\n\\nimport com.pushspring.sdk.PSRealtimeCustomerInsights;\\nimport com.pushspring.sdk.PushSpring;\\n\\nimport com.google.gson.internal.LinkedTreeMap;\\n\\n\\nimport java.util.ArrayList;\\nimport java.util.HashMap;\\nimport java.util.List;\\n\\n\\npublic class AdParameterConfig implements PSRealtimeCustomerInsights {\\n    private static String gender = \\\"u\\\";\\n    private static Double medianAge = 0.0;\\n    private static Double medianIncome = 0.0;\\n\\n    public AdParameterConfig()\\n    {\\n        PushSpring.sharedPushSpring().getRealtimeCustomerInsights(this);\\n    }\\n\\n    // for SDKs like AdMob or Doubleclick, where you need to supply gender and age when building an ad request, you can use these methods\\n    // Gender will be either 'm', 'f', or 'u' for unknown\\n    public static String getGender()\\n    {\\n        return gender;\\n    }\\n\\n    // age will be 0 if unknown\\n    public static int getAge()\\n    {\\n        if (medianAge == null)\\n        {\\n            return 0;\\n        }\\n        return medianAge.intValue();\\n    }\\n\\n    // income will be 0 if unknown\\n    public static int getIncome()\\n    {\\n        if (medianIncome == null)\\n        {\\n            return 0;\\n        }\\n        return medianIncome.intValue();\\n    }\\n\\n    @Override\\n    public void RealtimeCustomerInsightsResults(HashMap<String, Object> results) {\\n        String status = (String)results.get(\\\"status\\\");\\n        @SuppressWarnings(\\\"unchecked\\\") LinkedTreeMap<String,Object> responses = (LinkedTreeMap<String,Object>)results.get(\\\"responses\\\");\\n        @SuppressWarnings(\\\"unchecked\\\") ArrayList<String> personas = (ArrayList<String>) responses.get(\\\"personas\\\");\\n        AdParameterConfig.gender = (String) responses.get(\\\"gender\\\");\\n        // PushSpring Age and Income are range values, so we also return the median value for use with ad network parameters\\n        AdParameterConfig.medianAge = (Double) responses.get(\\\"medianAge\\\");\\n        AdParameterConfig.medianIncome = (Double) responses.get(\\\"medianIncome\\\");\\n    }\\n\\n    // returns an AdColonyUserMetadata class you can use on your intialization call to AdColony\\n//    public AdColonyUserMetadata getAdColonyUserMetadata()\\n//    {\\n//        AdColonyUserMetadata adColonyUserMetadata = new AdColonyUserMetadata();\\n//        if (AdParameterConfig.gender.equalsIgnoreCase(\\\"m\\\"))\\n//        {\\n//            adColonyUserMetadata.setUserGender(AdColonyUserMetadata.USER_MALE);\\n//        } else if (AdParameterConfig.gender.equalsIgnoreCase(\\\"f\\\"))\\n//        {\\n//            adColonyUserMetadata.setUserGender(AdColonyUserMetadata.USER_FEMALE);\\n//        }\\n//        if (AdParameterConfig.medianAge != null)\\n//        {\\n//            adColonyUserMetadata.setUserAge(medianAge.intValue());\\n//        }\\n//        if (AdParameterConfig.medianIncome != null)\\n//        {\\n//            adColonyUserMetadata.setUserAnnualHouseholdIncome(medianIncome.intValue());\\n//        }\\n//        return adColonyUserMetadata;\\n//    }\\n\\n    public String getMoPubKeywords()\\n    {\\n        String keywords = \\\"\\\";\\n\\n        if (AdParameterConfig.gender.equalsIgnoreCase(\\\"m\\\"))\\n        {\\n            keywords+=\\\"m_gender:m\\\";\\n        } else if (AdParameterConfig.gender.equalsIgnoreCase(\\\"f\\\"))\\n        {\\n            keywords+=\\\"m_gender:f\\\";\\n        }\\n        if (AdParameterConfig.medianAge != null)\\n        {\\n            if (keywords.length() > 0) { keywords+=\\\",\\\"; }\\n            keywords+=\\\"m_age:\\\"+medianAge.intValue();\\n        }\\n\\n        return keywords;\\n    }\\n\\n    public List<String> getAerServKeywords()\\n    {\\n        List <String> keywords = new ArrayList<String>();\\n\\n        if (AdParameterConfig.gender.equalsIgnoreCase(\\\"m\\\"))\\n        {\\n            keywords.add(\\\"men\\\");\\n            keywords.add(\\\"male\\\");\\n        } else if (AdParameterConfig.gender.equalsIgnoreCase(\\\"f\\\"))\\n        {\\n            keywords.add(\\\"women\\\");\\n            keywords.add(\\\"female\\\");\\n        }\\n\\n        return keywords;\\n    }\\n\\n// Amazon Ads\\n//    public AdTargetingOptions getAmazonAdTargetingOptions()\\n//    {\\n//        AdTargetingOptions adTargetingOptions = new AdTargetingOptions();\\n//\\n//        int age = AdParameterConfig.getAge();\\n//        if (age != 0)\\n//        {\\n//            adTargetingOptions.setAge(age);\\n//        }\\n//\\n//        return adTargetingOptions;\\n//    }\\n\\n// AOL One Mobile / Millennial Media\\n//    public com.millennialmedia.UserData getMillennialMediaUserData()\\n//    {\\n//        com.millennialmedia.UserData userData = new com.millennialmedia.UserData();\\n//        int age = AdParameterConfig.getAge();\\n//        int income = AdParameterConfig.getIncome();\\n//\\n//        if (AdParameterConfig.gender.equalsIgnoreCase(\\\"m\\\"))\\n//        {\\n//            userData.setGender(UserData.Gender.MALE);\\n//        } else if (AdParameterConfig.gender.equalsIgnoreCase(\\\"f\\\"))\\n//        {\\n//            userData.setGender(UserData.Gender.FEMALE);\\n//        }\\n//\\n//        if (age != 0)\\n//        {\\n//            userData.setAge(age);\\n//        }\\n//\\n//        if (income != 0)\\n//        {\\n//            userData.setIncome(income);\\n//        }\\n//\\n//        return userData;\\n//    }\\n\\n}\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"passing-parameters-to-ad-networks-1","type":"basic","title":"Android - Passing Parameters to Ad Networks"}

Android - 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().getRealtimeCustomerInsights()` 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. To help you glue the PushSpring data returned from this call into the various Ad Network SDKs you might be using, below we provide the source for a Java class called `AdParameterConfig` that you can include in your apps. This class is designed to be initialized right after you initialize the PushSpring SDK in your code, most likely in the "main" activity of your app at startup, with code like the following: [block:code] { "codes": [ { "code": "@Override\nprotected void onCreate(Bundle savedInstanceState) {\n\t super.onCreate(savedInstanceState);\n\t setContentView(R.layout.activity_main);\n\t\t\n PushSpring pushSpring = PushSpring.sharedPushSpring();\n pushSpring.onCreate(this, PS_API_KEY, googlePlayConnector);\n AdParameterConfig adParameterConfig = new AdParameterConfig();\n ...\n}\n", "language": "java" } ] } [/block] The `AdParameterConfig` class makes the necessary call to PushSpring to retrieve Gender, Age, and Household Income demographic data for the current device, and has methods you can use with various Ad Networks to configure this data into your ad calls. [block:api-header] { "title": "AdParameterConfig Class Source" } [/block] This class is meant as a sample that you can drop into an existing app and then modify as needed. To use it, copy it into your source tree, change the package information, and then uncomment the methods that are designed to work with your existing ad monetization partners. You can also use the generic methods `getAge()`, `getGender()`, and `getIncome()` and use that data to configure any other ad networks you need. Make sure you initialize this class soon after initializing the PushSpring SDK. [block:code] { "codes": [ { "code": "package com.pushspring.adnetworksample;\n\n// Uncomment any of the below you have embedded in your app\n//import com.adcolony.sdk.AdColonyUserMetadata;\n//import com.amazon.device.ads.AdTargetingOptions;\n//import com.millennialmedia.UserData;\n\nimport com.pushspring.sdk.PSRealtimeCustomerInsights;\nimport com.pushspring.sdk.PushSpring;\n\nimport com.google.gson.internal.LinkedTreeMap;\n\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\n\n\npublic class AdParameterConfig implements PSRealtimeCustomerInsights {\n private static String gender = \"u\";\n private static Double medianAge = 0.0;\n private static Double medianIncome = 0.0;\n\n public AdParameterConfig()\n {\n PushSpring.sharedPushSpring().getRealtimeCustomerInsights(this);\n }\n\n // for SDKs like AdMob or Doubleclick, where you need to supply gender and age when building an ad request, you can use these methods\n // Gender will be either 'm', 'f', or 'u' for unknown\n public static String getGender()\n {\n return gender;\n }\n\n // age will be 0 if unknown\n public static int getAge()\n {\n if (medianAge == null)\n {\n return 0;\n }\n return medianAge.intValue();\n }\n\n // income will be 0 if unknown\n public static int getIncome()\n {\n if (medianIncome == null)\n {\n return 0;\n }\n return medianIncome.intValue();\n }\n\n @Override\n public void RealtimeCustomerInsightsResults(HashMap<String, Object> results) {\n String status = (String)results.get(\"status\");\n @SuppressWarnings(\"unchecked\") LinkedTreeMap<String,Object> responses = (LinkedTreeMap<String,Object>)results.get(\"responses\");\n @SuppressWarnings(\"unchecked\") ArrayList<String> personas = (ArrayList<String>) responses.get(\"personas\");\n AdParameterConfig.gender = (String) responses.get(\"gender\");\n // PushSpring Age and Income are range values, so we also return the median value for use with ad network parameters\n AdParameterConfig.medianAge = (Double) responses.get(\"medianAge\");\n AdParameterConfig.medianIncome = (Double) responses.get(\"medianIncome\");\n }\n\n // returns an AdColonyUserMetadata class you can use on your intialization call to AdColony\n// public AdColonyUserMetadata getAdColonyUserMetadata()\n// {\n// AdColonyUserMetadata adColonyUserMetadata = new AdColonyUserMetadata();\n// if (AdParameterConfig.gender.equalsIgnoreCase(\"m\"))\n// {\n// adColonyUserMetadata.setUserGender(AdColonyUserMetadata.USER_MALE);\n// } else if (AdParameterConfig.gender.equalsIgnoreCase(\"f\"))\n// {\n// adColonyUserMetadata.setUserGender(AdColonyUserMetadata.USER_FEMALE);\n// }\n// if (AdParameterConfig.medianAge != null)\n// {\n// adColonyUserMetadata.setUserAge(medianAge.intValue());\n// }\n// if (AdParameterConfig.medianIncome != null)\n// {\n// adColonyUserMetadata.setUserAnnualHouseholdIncome(medianIncome.intValue());\n// }\n// return adColonyUserMetadata;\n// }\n\n public String getMoPubKeywords()\n {\n String keywords = \"\";\n\n if (AdParameterConfig.gender.equalsIgnoreCase(\"m\"))\n {\n keywords+=\"m_gender:m\";\n } else if (AdParameterConfig.gender.equalsIgnoreCase(\"f\"))\n {\n keywords+=\"m_gender:f\";\n }\n if (AdParameterConfig.medianAge != null)\n {\n if (keywords.length() > 0) { keywords+=\",\"; }\n keywords+=\"m_age:\"+medianAge.intValue();\n }\n\n return keywords;\n }\n\n public List<String> getAerServKeywords()\n {\n List <String> keywords = new ArrayList<String>();\n\n if (AdParameterConfig.gender.equalsIgnoreCase(\"m\"))\n {\n keywords.add(\"men\");\n keywords.add(\"male\");\n } else if (AdParameterConfig.gender.equalsIgnoreCase(\"f\"))\n {\n keywords.add(\"women\");\n keywords.add(\"female\");\n }\n\n return keywords;\n }\n\n// Amazon Ads\n// public AdTargetingOptions getAmazonAdTargetingOptions()\n// {\n// AdTargetingOptions adTargetingOptions = new AdTargetingOptions();\n//\n// int age = AdParameterConfig.getAge();\n// if (age != 0)\n// {\n// adTargetingOptions.setAge(age);\n// }\n//\n// return adTargetingOptions;\n// }\n\n// AOL One Mobile / Millennial Media\n// public com.millennialmedia.UserData getMillennialMediaUserData()\n// {\n// com.millennialmedia.UserData userData = new com.millennialmedia.UserData();\n// int age = AdParameterConfig.getAge();\n// int income = AdParameterConfig.getIncome();\n//\n// if (AdParameterConfig.gender.equalsIgnoreCase(\"m\"))\n// {\n// userData.setGender(UserData.Gender.MALE);\n// } else if (AdParameterConfig.gender.equalsIgnoreCase(\"f\"))\n// {\n// userData.setGender(UserData.Gender.FEMALE);\n// }\n//\n// if (age != 0)\n// {\n// userData.setAge(age);\n// }\n//\n// if (income != 0)\n// {\n// userData.setIncome(income);\n// }\n//\n// return userData;\n// }\n\n}\n", "language": "java" } ] } [/block]