title: Using Google Analytics in Silverlight 4
body: <p><br>
  I am trying to integrate google analytics in to my silverlight 4 out of browser application. When i add my Google Analytics code in my XAML like the following: <br></p>
  
  <pre><code>    &lt;i:Interaction.Behaviors&gt;
          &lt;ga:GoogleAnalytics WebPropertyId="xxxxxxxxxxxxx"/&gt;
      &lt;/i:Interaction.Behaviors&gt;
  </code></pre>
  
  <p>I am getting an error which is 
  <strong><em>"Add value to collection of type 'System.Windows.Interactivity.BehaviorCollection' threw an exception."</em></strong>  <br></p>
  
  <p>I am not able to find much of a help in the net regarding this, few pointed out at my user control code which is : <br></p>
  
  <p>xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" </p>
  
  <p>currently i am using VS 2010 and Blend 4 for this. <br>
  Thanks for reading this and if you are able to help me out in this issue it would be great. <br><br></p>
  
  <p>EDITED:</p>
  
  <p>As Mentioned I am putting the data here:</p>
  
  <p>In my App.xaml </p>
  
  <pre><code>&lt;Application   
    x:Class="SilverlightApp.slate.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mwa="clr-namespace:Microsoft.WebAnalytics;assembly=Microsoft.WebAnalytics"
               xmlns:ga="clr-namespace:Google.WebAnalytics;assembly=Google.WebAnalytics"&gt;
  
  
      &lt;Application.Resources&gt;
          &lt;ResourceDictionary&gt;
              &lt;ResourceDictionary.MergedDictionaries&gt;
                  &lt;ResourceDictionary Source="Assets/Styles.xaml"/&gt;
                  &lt;ResourceDictionary Source="CustomControls.xaml"/&gt;
              &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
  
      &lt;/Application.Resources&gt;
  
      &lt;Application.ApplicationLifetimeObjects&gt;
          &lt;mwa:WebAnalyticsService&gt;
              &lt;mwa:WebAnalyticsService.Services&gt;
                  &lt;ga:GoogleAnalytics WebPropertyId="XXXXXXXXXXXXX" /&gt;
              &lt;/mwa:WebAnalyticsService.Services&gt;
          &lt;/mwa:WebAnalyticsService&gt;
      &lt;/Application.ApplicationLifetimeObjects&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>In the Main Page.XAML under the Grid :</p>
  
  <pre><code>  &lt;Button x:Name="btn_library_Icon" Margin="86,2,64,6" Style="{StaticResource menu_librarybuttonstyle}" FontFamily="/SilverlightApp.slate;component/Fonts/Fonts.zip#Segoe UI" FontSize="9.333" Click="btn_library_Icon_Click"&gt;
                  &lt;i:Interaction.Triggers&gt;
                      &lt;i:EventTrigger SourceName="btn_library_Icon" EventName="Click"&gt;
                          &lt;mwab:TrackAction Category="Library Accessed"/&gt;
                      &lt;/i:EventTrigger&gt;
                  &lt;/i:Interaction.Triggers&gt;
                  &lt;Image x:Name="image" Source="Assets/icon_menu_library.png" Stretch="Fill" Width="23" Height="23"/&gt;
             &lt;/Button&gt;
  </code></pre>
  
  <p>when i run this it gives me an error as :
  <strong>"Add value to collection of type 'System.Windows.Interactivity.TriggerCollection' threw an exception."</strong></p>
  
  <p>Am i Missing something here?</p>