SolvedPrivate

google analytics 2 top level domains

Posted on 2014-09-03
3
37 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

A great marketing strategy is diverse.  Read about the not so popular, yet effective, marketing tactics you can start using today!
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

685 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