google-analyticsanalyticsgoal-tracking

Push Goals only 1 account in 2 Google Analytics codes in site


I not sure with my title, Just edit me if you have a better

Okey, I have 2 Google Analytics codes in my site.

<script type="text/javascript">
              var _gaq = _gaq || [];
              _gaq.push(['_setAccount', 'UA-XXX-A']);
              _gaq.push(['_trackPageview']);
              (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
              })();
</script>
<script type="text/javascript">
              var _gaq = _gaq || [];
              _gaq.push(['_setAccount', 'UA-XXX-B']);
              _gaq.push(['_trackPageview']);
              (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
              })();
</script>

And I push my goal like..

_gaq.push(['_trackEvent','Form','Submitted','Test']);

How to make this goal tracking for UA-XXX-A only?


Solution

  • Best practices for using multiple profiles is to name the secondary trackers -- see Google docs for the _gaq.push(). Any analytics calls in the page (like your _trackEvent call) that don't use a name will use the first (default) tracker.

    Also, you're loading the analytics code twice. Loading it once will speed up your page and give you more reproducible data collection.

    Try

    <script type="text/javascript">
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXX-A']);
      _gaq.push(['_trackPageview']);
      _gaq.push(['t2._setAccount', 'UA-XXX-B']);
      _gaq.push(['t2._trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>