SolvedPrivate

google analytics 2 top level domains

Posted on 2014-09-03
3
34 Views
Last Modified: 2016-02-24
Hello,
I have inherited a website that uses the same HTML code base for two top level domains for example www.domain123z.com and www.domain456z.com.

I would like to record visitor sessions into separate properties in google analytics. So I will know X amount of visitors used domain123z.com and X amount of visitors used domain456z.com

Is this possible in google analytics?  I am using ga.async what would my tracking look like?

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-123456-1']);
  _gaq.push(['_setDomainName', 'domain123z.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

  _gaq.push(['_setAccount', 'UA-123456-2']);
  _gaq.push(['_setDomainName', 'domain456z.com']);
  _gaq.push(['_setAllowLinker', true]);
  _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>

Open in new window


Thank You.
0
Comment
Question by:jay_eire
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40302377
what about :

<script type="text/javascript">

  var _gaq = _gaq || [];

if(location.host.match(/\.?([^.]*)\.com/).pop() == "domain123z") {

  _gaq.push(['_setAccount', 'UA-123456-1']);
  _gaq.push(['_setDomainName', 'domain123z.com']);
  _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);
}
else {
  _gaq.push(['_setAccount', 'UA-123456-2']);
  _gaq.push(['_setDomainName', 'domain456z.com']);
  _gaq.push(['_setAllowLinker', true]);
  _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>

Open in new window

0
 
LVL 7

Author Comment

by:jay_eire
ID: 40307873
thank you for reply I will check this out.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40308135
np
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
The Best Website Creation Tools 14 53
Uncaught Type error cannot assign to read only property 6 25
Fulfillment API php code sample 1 37
Simple Total function not working 8 30
Learn about the eCommerce marketing trends for the year ahead.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
This video teaches users how to migrate an existing Wordpress website to a new domain.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now