WP8 Adrotator not initialising at start

Jul 19, 2014 at 4:39 PM
Edited Jul 19, 2014 at 9:48 PM
Hi I have added Adrotator to my Windows Phone 8 app using Microsoft Pub and AdDuplex. The problem I'm having is the ads are not starting when the app starts. If I navigate away and back to the main page then the add begins and starts it's feed.

I have tried putting the follwoing in OnPageLoaded and OnNavigatedTo
            try
            {
                Debug.WriteLine("In start of ivalidate");
                // Call for AdRotator
                AdRot2.Invalidate();
                AdRot3.Invalidate();
                AdRot4.Invalidate();
                AdRot5.Invalidate();
                AdRot6.Invalidate();

                AdRot2.Log += AdRot2_Log;
                AdRot3.Log += AdRot3_Log;
                AdRot4.Log += AdRot4_Log;
                AdRot5.Log += AdRot5_Log;
                AdRot6.Log += AdRot6_Log;

                Debug.WriteLine("In end of invalidate");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("AdRotator failed to invalidate! exception= " + ex.Message);
            }
The log method is:
        void AdRot2_Log(string message)
        {
            Debug.WriteLine("AdRot2:\r\n" + message);
        }
Debug display the following when the app starts:

In WelcomePage_Loaded()
In start of ivalidate
In end of invalidate

No log info!
Debug then displays the following when I navigate away from the page and back again:

In WelcomePage_Loaded()
In start of ivalidate
AdRot2:
Ads are enabled for display
AdRot2:
Testing "PubCenter" - Result True
AdRot2:
Testing "AdDuplex" - Result True
AdRot2:
Ads being requested for: PubCenter
AdRot2:
Ads being served for: PubCenter
AdRot2:
Ads being served for: PubCenter
AdRot3:
Ads are enabled for display
AdRot3:
Testing "PubCenter" - Result True
AdRot3:
Testing "AdDuplex" - Result True
AdRot3:
Ads being requested for: PubCenter
AdRot3:
Ads being served for: PubCenter
AdRot3:
Ads being served for: PubCenter
AdRot4:
Ads are enabled for display
AdRot4:
Testing "PubCenter" - Result True
AdRot4:
Testing "AdDuplex" - Result True
AdRot4:
Ads being requested for: PubCenter
AdRot4:
Ads being served for: PubCenter
AdRot4:
Ads being served for: PubCenter
AdRot5:
Ads are enabled for display
AdRot5:
Testing "PubCenter" - Result True
AdRot5:
Testing "AdDuplex" - Result True
AdRot5:
Ads being requested for: PubCenter
AdRot5:
Ads being served for: PubCenter
AdRot5:
Ads being served for: PubCenter
AdRot6:
Ads are enabled for display
AdRot6:
Testing "PubCenter" - Result True
AdRot6:
Testing "AdDuplex" - Result True
AdRot6:
Ads being requested for: AdDuplex
AdRot6:
Ads being served for: AdDuplex
AdRot6:
Ads being served for: AdDuplex
In end of invalidate
AdRot2:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot2:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot2:
Ads failed request for: PubCenter
AdRot2:
Ads failed request for: PubCenter
AdRot3:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot3:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot3:
Ads failed request for: PubCenter
AdRot3:
Ads failed request for: PubCenter
AdRot4:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot4:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot4:
Ads failed request for: PubCenter
AdRot4:
Ads failed request for: PubCenter
AdRot5:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot5:
PubCenter Failed: You can not use PubCenter IDs for testing in the emulator. If you want to test with these IDs, please deploy your application to a device. Otherwise please change your ApplicationId to "test_client" and AdUnitId to one of the supported ad types as outlined in the documentation.
AdRot5:
Ads failed request for: PubCenter
AdRot5:

Etc Etc

whats wrong here, dont know what to try next to get the ad working on first load?

The ad is on a panorama page with the following code:
            <phone:PanoramaItem HeaderTemplate="{StaticResource MyPanoramaHeaderTemplate}" Name="panoItem1" CacheMode="{x:Null}" HorizontalAlignment="Left" Header="Main Menu" Height="629" Width="480" VerticalAlignment="Bottom" FontFamily="/ContosoSocial;component/Fonts/Fonts.zip#PerryGothic" Foreground="Black" FontSize="34" >
                <phone:PanoramaItem.RenderTransform>
                    <TranslateTransform/>
                </phone:PanoramaItem.RenderTransform>

                <ScrollViewer Background="{x:Null}" ScrollViewer.VerticalScrollBarVisibility="Visible" BorderBrush="{x:Null}" Margin="-19,-51,-1,2" HorizontalAlignment="Left" Height="573" Width="488" Foreground="White" VerticalAlignment="Bottom" >
                    <StackPanel Orientation="Vertical" VerticalAlignment="Top" Height="Auto" HorizontalAlignment="Left" Width="488">
                        <StackPanel Orientation="Vertical" Height="Auto" HorizontalAlignment="Left" Margin="7,0,0,0" Width="481">

<AdRotator:AdRotatorControl 
                                x:Name="AdRot2" 
                                Height="80"
                                Width="480"
                                DefaultSettingsFileUri="/ContosoSocial;component/defaultAdSettings.xml"
                                SettingsUrl="http://adrotator.apphb.com/defaultAdSettingsWindows8dev.xml"
                                DefaultAdType="AdDuplex"
                                PubCenterAdUnitId="MyID-etc"
                                PubCenterAppId="MyID-etc"
                                AdDuplexAppId="MyId-etc"
                                IsAdRotatorEnabled="True"
                                SlidingAdDirection="Left"
                                SlidingAdDisplaySeconds="10"
                                SlidingAdHiddenSeconds="2"
                                Margin="0,2,1,2"
                                />
If I place an add in the second page I navigate to then that works fine when I navigate to it, but the ads on the first page never work until I navigate away and back again.

Please help with this problem.

Solution Explored properties display that I'm using AdRotator version 1.0.3
this is happening both on emulator and on device.
Coordinator
Jul 21, 2014 at 4:30 PM
Interesting, cannot see anything offhand as to why your project could not display on startup. If possible could you put together a quick sample project and we'll look in to it.

Alternatively, you could upgrade to the V2 control now hosted over at https://github.com/Adrotator/AdrotatorV2 and on NuGet http://www.nuget.org/packages/AdRotator/2.0.0
Jul 21, 2014 at 7:45 PM
Edited Jul 21, 2014 at 7:53 PM
Hi Darkside, thanks for the relpy. I tried calling Invalidte many ways but what I think eventually worked was adding the following to OnLoaded:
            // Check for trial licnece before adding ad's
            if ((TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.Trial) ||
                (TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.MissingOrRevoked))
            {
                // Kick start AdRotator & AdDuplex controls
                try
                {
                    // Call for AdRotator & AdDuplex controls
                    AdRot2.Invalidate();
                    AdRot3.Invalidate();
                    AdRot4.Invalidate();
                    AdRot5.Invalidate();
                    AdRot6.Invalidate();

                    AdRot2.Visibility = Visibility.Visible;
                    AdRot2.IsEnabled = true;
                    AdRot3.Visibility = Visibility.Visible;
                    AdRot3.IsEnabled = true;
                    AdRot4.Visibility = Visibility.Visible;
                    AdRot4.IsEnabled = true;
                    AdRot5.Visibility = Visibility.Visible;
                    AdRot5.IsEnabled = true;
                    AdRot6.Visibility = Visibility.Visible;
                    AdRot6.IsEnabled = true;

                    // Register handlers for log information
                    AdRot2.Log += AdRot2_Log;
                    AdRot3.Log += AdRot3_Log;
                    AdRot4.Log += AdRot4_Log;
                    AdRot5.Log += AdRot5_Log;
                    AdRot6.Log += AdRot6_Log;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("AdRotator failed to invalidate! exception= " + ex.Message);
                }
            }
        }
Also the following loaded event code:
        // Call AdRotator Invalidate to start ad's
        private void AdRot2_Loaded(object sender, RoutedEventArgs e)
        {
            // Check for trial licnece before adding ad's
            if ((TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.Trial) ||
                (TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.MissingOrRevoked))
            {
                try
                {
                    AdRot2.Invalidate();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("AdRotator failed to invalidate! exception= " + ex.Message);
                }
            }
        }
Below is code in OnNavigatedFrom
            AdRot2.Dispose();
            AdRot3.Dispose();
            AdRot4.Dispose();
            AdRot5.Dispose();
            AdRot6.Dispose();

            // Collect resources from Garbage
            //GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            System.GC.Collect();
Below is the .xaml control code:
                            <AdRotator:AdRotatorControl 
                                x:Name="AdRot2" 
                                Height="80"
                                Width="480"
                                DefaultSettingsFileUri="/ContosoSocial;component/defaultAdSettings.xml"
                                SettingsUrl="http://XXXXXXXXXXX.com/GOTRemoteFiles/GOTRemoteAdRotSettings.xml"
                                DefaultAdType="PubCenter"
                                PubCenterAdUnitId="XXXX"
                                PubCenterAppId="ba595004-2934-4cfe-XXXXXXXXXXXXX"
                                AdDuplexAppId="XXXXXXXXX"
                                IsAdRotatorEnabled="True"
                                SlidingAdDirection="Left"
                                SlidingAdDisplaySeconds="10"
                                SlidingAdHiddenSeconds="2"
                                Margin="0,2,1,2" Loaded="AdRot2_Loaded"
                                />
And below is the local and remote .xml config file:
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CultureDescriptors>
    <AdCultureDescriptor CultureName="en-US">
      <Probabilities Probability="90" AdType="PubCenter"  />
      <Probabilities Probability="10" AdType="AdDuplex" />
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="en-GB">
      <Probabilities Probability="10" AdType="AdDuplex" />
      <Probabilities Probability="90" AdType="PubCenter" />
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="de-DE">
      <Probabilities Probability="90" AdType="PubCenter" />
      <Probabilities Probability="10" AdType="AdDuplex" />
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="default">
      <Probabilities Probability="90" AdType="PubCenter" />
      <Probabilities Probability="10" AdType="AdDuplex" />
    </AdCultureDescriptor>
  </CultureDescriptors>
</AdSettings>
This seems to work now and I also added a remote .xml config file too. The onlt defference I can see now is sometines they display the "An Example Remote Default House Ad"! I'm assuming this is a default ad if it can't pick anything up? Nothing happens when clicked either. Not sure why this is? This happens on both emulator and phone. Why is this?

I tried the AdRotator v2 beta yesterday but ran into troubles with it and as we are only 6 days from launch I figured it's to late in the day now...

...Although the link you provided looks like a later "stable release" I'll give it another try today and get back to you later! In the mean time could you clear up why AdRotator now sometimes displays the "An Example Remote Default House Ad" as if this happens on a regular basis when goes to market them not good!

Once again many thanks for your reply.
Coordinator
Jul 21, 2014 at 8:29 PM
Glad you're working. A couple of points though. ( although the docs state you should unit in onloaded 😝)

• you have configured adunits in both xaml AND in your config file. Don't do that its supposed to either/or 😎 and we recommend just putting it in your config xml
• you have the same ad config for all cultures, should just have the default culture in that case. You only add variants if the config is different for a culture
• the default ad is most likely showing up because its configured in your xml (either in the file or programmatically) pointing to our test version. (or its cached on your test device if you ran it before changing your config, try uninstalling and retesting if that is the case on the device)

With regards to V2, the only major difference is the config file as it has a different schema, but if your working now and have a deadline then leave it till the next update 😎

Hope your launch goes well
Jul 21, 2014 at 9:14 PM
Edited Jul 21, 2014 at 9:27 PM
Hi Darkside, again many thanks for your reply.

I have changed the .xml config file to include the adUnit information only which is what I'm assuming your refering to whith either/or?

As follows:
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CultureDescriptors>
    <AdCultureDescriptor CultureName="en-US">
      <Probabilities Probability="90" AdType="PubCenter" AppID="ba595004-2934-4cfe-b783-XXXXXXXXXXXX" SecondaryID="180573" />
      <Probabilities Probability="10" AdType="AdDuplex"  AppID="107339"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="en-GB">
      <Probabilities Probability="10" AdType="AdDuplex"  AppID="107339"/>
      <Probabilities Probability="90" AdType="PubCenter" AppID="ba595004-2934-4cfe-b783-XXXXXXXXXXXX" SecondaryID="180573"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="de-DE">
      <Probabilities Probability="90" AdType="PubCenter" AppID="ba595004-2934-4cfe-b783-XXXXXXXXXXXX" SecondaryID="180573"/>
      <Probabilities Probability="10" AdType="AdDuplex"  AppID="107339"/>
    </AdCultureDescriptor>
    <AdCultureDescriptor CultureName="default">
      <Probabilities Probability="90" AdType="PubCenter" AppID="ba595004-2934-4cfe-b783-XXXXXXXXXXXX" SecondaryID="180573"/>
      <Probabilities Probability="10" AdType="AdDuplex"  AppID="107339"/>
    </AdCultureDescriptor>
  </CultureDescriptors>
</AdSettings>
The .xaml is now:
<AdRotator:AdRotatorControl 
                                x:Name="AdRot2" 
                                Height="80"
                                Width="480"
                                DefaultSettingsFileUri="/ContosoSocial;component/defaultAdSettings.xml"
                                SettingsUrl="http://XXXXXXXXX.com/GOTRemoteFiles/GOTRemoteAdRotSettings.xml"
                                DefaultAdType="PubCenter"
                                
                                SlidingAdDirection="Left"
                                SlidingAdDisplaySeconds="10"
                                SlidingAdHiddenSeconds="2"
                                Margin="0,2,1,2" Loaded="AdRot2_Loaded"
                                />
I'm am assuming I have the AppID & secondaryID around the right way. The reason I had them set in .xaml was I wanted to be able to use several AdDuplex and PubCenter units within the code thus only referencing a single .xml config and each unit defining its own units. If thats your recommendation that I suppose a work around would be each AdRotator unit to reference a seperate .xml file for different AdDuplex & PubCentre units. EG I have several AdDuplex units with varying styles (not sure which is better or what will have a better response) so seperate units I will be able to gague what works better etc.

With regard to cultures and probability etc, I only have PubCentre and adDuplex configured for now and was hoping to include AdMob when it's compatible. How does the probability work, is there a default config for using just AdDuplex and PubCentre etc.

Please excuse inexperience I'm still at University and am attempting to develop my first product here so started from scratch only a few months ago, everything is still new!

All help much appreciated.
Coordinator
Jul 21, 2014 at 11:55 PM
Looks good, basically your config xml only needs to look like this
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CultureDescriptors>
    <AdCultureDescriptor CultureName="default">
      <Probabilities Probability="90" AdType="PubCenter" AppID="ba595004-2934-4cfe-b783-XXXXXXXXXXXX" SecondaryID="180573"/>
      <Probabilities Probability="10" AdType="AdDuplex"  AppID="107339"/>
    </AdCultureDescriptor>
  </CultureDescriptors>
</AdSettings>
Since your only using the same template for each culture. You would only add other CutureDescriptures if you wanted different providers to different probabilities for each region.

Yes your Pubcenter config is fine.

The probabilities determine how often a provider will present ads (providing they have ads to display). so Pubcentre being 90% means it will show up roughly 90% of the time. If pubcenter fails then it will fall back to adduplex (adDuplex ALWAYS shows exchange ads)

In V1 you can only have one instance of each provider per culture, you can update it regularly in your remote XML, that's down to you to manage. One of the major differences in V2 is that you can have multiple configs for a provider in each culture. So 5 different AdDuplex ID's if you wish.

As for the multiple config files, that's up to you. just depends how often you want to poll the same Ad ID's as providers usually only give you the same ad if you ask too often and then it doesn't count (except AdDuplex). Having multiple config files means you can configure multiple Ad ID's

Hope this helps.

Should be writing some posts about V2 soon, but as I stated, best leave that to your next update with release so soon.