Beispiel #1
0
        public static AdRequest BuildAdRequest()
        {
            var builder = new AdRequest.Builder();

            foreach (var deviceId in  UM_GoogleAdsSettings.Instance.TestDevices)
            {
                builder.AddTestDevice(deviceId);
            }

            foreach (var keyword in UM_GoogleAdsSettings.Instance.Keywords)
            {
                builder.AddKeyword(keyword);
            }

            builder.TagForChildDirectedTreatment(UM_GoogleAdsSettings.Instance.TagForChildDirectedTreatment);


            if (UM_GoogleAdsSettings.Instance.NPA)
            {
                builder.AddExtra("npa", "1");
            }

            if (UM_GoogleAdsSettings.Instance.Gender != Gender.Unknown)
            {
                builder.SetGender(UM_GoogleAdsSettings.Instance.Gender);
            }

            if (UM_GoogleAdsSettings.Instance.Birthday != DateTime.MinValue)
            {
                builder.SetBirthday(UM_GoogleAdsSettings.Instance.Birthday);
            }

            return(builder.Build());
        }
Beispiel #2
0
        public static AdRequest BuildRequest(TDAdConfig data)
        {
            var builder = new AdRequest.Builder();

            if (m_Config.isDebugMode)
            {
                builder.AddTestDevice("54A21F94407E31BD8A20879613096F8B");
            }

            if (!string.IsNullOrEmpty(data.keyword))
            {
                builder.AddKeyword(data.keyword);
            }
            builder.SetGender((Gender)data.gender);
            if (data.isBirthDayConfiged)
            {
                builder.SetBirthday(data.GetBirthDayTime());
            }

            if (data.forFamilies)
            {
                builder.AddExtra("is_designed_for_families", "true");
            }

            if (data.forChild)
            {
                builder.TagForChildDirectedTreatment(true);
            }

            return(builder.Build());
        }
Beispiel #3
0
        private AdRequest CreateAdMobAdRequest()
        {
            AdRequest.Builder adBuilder = new AdRequest.Builder();

            // Targeting settings.
            var targeting = globalAdSettings.AdMobTargeting;

            // Gender.
            if (targeting.gender != AdSettings.TargetGender.Unspecified)
            {
                adBuilder.SetGender(
                    targeting.gender == AdSettings.TargetGender.Male ?
                    GoogleMobileAds.Api.Gender.Male :
                    GoogleMobileAds.Api.Gender.Female
                    );
            }

            // Birthday.
            if (targeting.setBirthday)
            {
                adBuilder.SetBirthday(targeting.birthday);
            }

            // Child-directed.
            if (targeting.tagForChildDirectedTreatment != AdSettings.ChildDirectedTreatmentOption.Unspecified)
            {
                adBuilder.TagForChildDirectedTreatment(targeting.tagForChildDirectedTreatment == AdSettings.ChildDirectedTreatmentOption.Yes);
            }

            // Extras.
            if (targeting.extras != null)
            {
                foreach (var extra in targeting.extras)
                {
                    if (!string.IsNullOrEmpty(extra.key) && !string.IsNullOrEmpty(extra.value))
                    {
                        adBuilder.AddExtra(extra.key, extra.value);
                    }
                }
            }

            // Test mode.
            if (globalAdSettings.AdMobEnableTestMode)
            {
                // Add all emulators
                adBuilder.AddTestDevice(AdRequest.TestDeviceSimulator);

                // Add user-specified test devices
                for (int i = 0; i < globalAdSettings.AdMobTestDeviceIds.Length; i++)
                {
                    adBuilder.AddTestDevice(Helper.AutoTrimId(globalAdSettings.AdMobTestDeviceIds[i]));
                }
            }

            return(adBuilder.Build());
        }
        public AdRequest CreateAdRequest()
        {
            AdRequest.Builder builder = new AdRequest.Builder();

            builder = builder.AddTestDevice(AdRequest.TestDeviceSimulator);
            for (int i = 0; i < testDevices.Length; i++)
            {
                builder = builder.AddTestDevice(testDevices[i]);
            }
            builder = builder.SetGender(targetGender);

            return(builder.Build());
        }
Beispiel #5
0
    public void BuildInterstitial()
    {
        failedLoading = false;
        interstitial  = new InterstitialAd(adUnitID);
        // Events
        interstitial.AdClosed          += HandleInterstitialClosed;
        interstitial.AdClosing         += HandleInterstitialClosing;
        interstitial.AdFailedToLoad    += HandleInterstitialFailedToLoad;
        interstitial.AdLeftApplication += HandleLeftApplication;
        interstitial.AdLoaded          += HandleLoaded;
        interstitial.AdOpened          += HandleOpened;
        // AdRequest
        AdRequest.Builder builder = new AdRequest.Builder();
        if (useEmulatorAsATestDevice)
        {
            builder.AddTestDevice(AdRequest.TestDeviceSimulator);
        }
        if (testDeviceIDs != null && testDeviceIDs.Length > 0)
        {
            foreach (string testDeviceID in testDeviceIDs)
            {
                builder.AddTestDevice(testDeviceID);
            }
        }
        if (keywords != null && keywords.Length > 0)
        {
            foreach (string keyword in keywords)
            {
                builder.AddKeyword(keyword);
            }
        }
        if (gender.HasValue)
        {
            builder.SetGender(gender.Value);
        }
        if (childDirectedTreatment.HasValue)
        {
            builder.TagForChildDirectedTreatment(childDirectedTreatment.Value);
        }
        AdRequest request = builder.Build();

        interstitial.LoadAd(request);
    }
    private AdRequest getAdRequest()
    {
        // Creating the request builder
        AdRequest.Builder requestBuilder = new AdRequest.Builder();

        // Test devices
        if (useEmulatorAsATestDevice)
        {
            requestBuilder.AddTestDevice(AdRequest.TestDeviceSimulator);
        }
        foreach (string deviceID in testDevices)
        {
            if (!string.IsNullOrEmpty(deviceID))
            {
                requestBuilder.AddTestDevice(deviceID);
            }
        }

        // Keywords
        string[] words = keywords.Split(',');
        foreach (string word in words)
        {
            if (word.Trim() != string.Empty)
            {
                requestBuilder.AddKeyword(word.Trim());
            }
        }

        // Gender
        if (gender != Gender.Unknown)
        {
            requestBuilder.SetGender(gender);
        }

        // Tag for child directed treatment
        if (tagForChildDirectedTreatment != TagForChildDirectedTreatment.NotTagged)
        {
            requestBuilder.TagForChildDirectedTreatment(tagForChildDirectedTreatment == TagForChildDirectedTreatment.True);
        }

        return(requestBuilder.Build());
    }
Beispiel #7
0
        AdRequest GetRequest(Dictionary <string, string> advertisingTargetInfo)
        {
            var request = new AdRequest.Builder();

            request.AddTestDevice(AdRequest.DeviceIdEmulator);
            request.AddTestDevice("260661DE96DFEDE845160916AD01F3CA"); //samsung tablet

            //Gender
            var gender = Gender.Unknown;

            if (advertisingTargetInfo.ContainsKey(AdKeyGender))
            {
                gender = advertisingTargetInfo[AdKeyGender].Equals("female", StringComparison.InvariantCultureIgnoreCase) ? Gender.Female : Gender.Male;
                request.SetGender((int)gender);
            }

            //Location
            var location = RealmServices.GetLastUserLocation();

            if (location != null)
            {
                var loc = new Android.Locations.Location("");
                loc.Latitude  = location.Latitude;
                loc.Longitude = location.Longitude;
                loc.Accuracy  = 1;
                request.SetLocation(loc);
            }

            //Birthday
            if (advertisingTargetInfo.ContainsKey(AdKeyBirthday))
            {
                var birthday = DateTime.ParseExact(advertisingTargetInfo[AdKeyBirthday], "MM/dd/yyyy", null);
                var bith     = new Java.Util.Date(birthday.Year, birthday.Month, birthday.Day);
                request.SetBirthday(bith);
            }

            return(request.Build());
        }
Beispiel #8
0
    // Returns an ad request with custom ad targeting. Modified to be more dynamic and adjustable from editor.
    private AdRequest CreateAdRequest()
    {
        AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

        if (testConfiguration.testDevicesEnabled == true)
        {
            adRequestBuilder.AddTestDevice(AdRequest.TestDeviceSimulator);
            foreach (string s in testConfiguration.testDevices)
            {
                adRequestBuilder.AddTestDevice(s);
            }
        }

        foreach (string s in keyWords)
        {
            adRequestBuilder.AddKeyword(s);
        }

        if (targetAudience.genderConfig.enable == true)
        {
            adRequestBuilder.SetGender(targetAudience.genderConfig.gender);
        }

        if (targetAudience.birthday.enable == true)
        {
            adRequestBuilder.SetBirthday(new DateTime(targetAudience.birthday.year, targetAudience.birthday.month, targetAudience.birthday.day));
        }


        if (targetAudience.TagForChildDirectedTreatment.enable == true)
        {
            switch (targetAudience.TagForChildDirectedTreatment.yesNo)
            {
            case E_YES_NO.yes:
                adRequestBuilder.TagForChildDirectedTreatment(true);
                break;

            case E_YES_NO.no:
                adRequestBuilder.TagForChildDirectedTreatment(false);
                break;

            default:
                //don't add option
                break;
            }
        }

        if (targetAudience.tag_for_under_age_of_consent.enable == true)
        {
            switch (targetAudience.tag_for_under_age_of_consent.yesNo)
            {
            case E_YES_NO.yes:
                adRequestBuilder.AddExtra("tag_for_under_age_of_consent", "true");
                break;

            case E_YES_NO.no:
                adRequestBuilder.AddExtra("tag_for_under_age_of_consent", "false");
                break;

            default:
                //don't add option
                break;
            }
        }

        if (targetAudience.max_ad_content_rating.enable == true)
        {
            adRequestBuilder.AddExtra("max_ad_content_rating", targetAudience.max_ad_content_rating.ToString());
            mPrint("max_ad_content_rating:'" + targetAudience.max_ad_content_rating.ToString() + "'.");
        }

        return(adRequestBuilder.Build());

        /*return new AdRequest.Builder()
         *  .AddTestDevice(AdRequest.TestDeviceSimulator)
         *  .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
         *  .AddKeyword("game")
         *  .SetGender(Gender.Male)
         *  .SetBirthday(new DateTime(1985, 1, 1))
         *  .TagForChildDirectedTreatment(false)
         *  .AddExtra("color_bg", "9B30FF")
         *  .Build();*/
    }