SolvedPrivate

google analytics 2 top level domains

Posted on 2014-09-03
3
42 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Building a cohesive image for your brand is vital to making an impression on consumers. When the economy is tough, brands do better than unbranded  products. This can have a huge impact on your long-term profits, as the economy goes up and down.
This article discusses how to implement server side field validation and display customized error messages to the client.
This video teaches users how to migrate an existing Wordpress website to a new domain.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

695 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