I have two websites:
http://unit.example.edu
and
http://m.unit.example.edu
The second website is a smartphone version (simplified, just a few pages of basic information) of the first website. The first website already has google analytics code there.
The top of the pages of the first website has code for detecting a visitor's device. If it is smartphone, directs the access to the mobile website. The first website's google analytics code is in the bottom of its pages.
Now I need to put google analytics into the second website.
I hope to be able to see the combined stats of both websites without manual addition. If possible, I also I want to see the stat of just for the second mobile website.
Should I just reuse the google analytics code (see below) in the second website? What is the right way?
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." :
"http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-YYYYYYY-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
Regards.
As requested, an answer.
I'd keep only the UA (Universal Analytics) tracking script on both sites. Make sure you test it first before relying on it to gather data correctly (easily monitored via analytics' real time metrics). Then set the proper views and filters. You can make multiple views to make sure you have everything set up correctly. One view should always be unfiltered (in case something is wrong with one of your filters; GA doesn't save filtered out data).
Related
I got an email from Google requesting a change to my AdWords conversion tracking setup. They want me to add new library "gtag.js" and some calls to a "gtag" function.
This seems pretty easy. In my research, though, I've read some things that give me pause, e.g.
"If you have Universal Analytics code on-page and are using any sort of customization to send events, virtual pageviews or other unique data to Analytics, you will likely not want to switch to gtag.js. That would mean updating all on-page customized code to the new gtag syntax. Not sure if you have custom code? Any use of custom dimensions, custom metrics, or events is likely relying on your current implantation of Universal Analytics."
(Source: https://www.bounteous.com/insights/2018/01/30/guide-adwords-conversion-tracking-2018/)
I definitely have Universal Analytics calls in place; I'm not 100% sure what they mean by "on-page" (where else would they be?) but I suspect my stuff qualifies. As for "customization," I do make use of the numbered dimensions (e.g. ga('set', 'dimension4', creditStatusCode) )
Does this really mean I should avoid gtag.js, though? I'm thinking not, but I'd also like to understand what that Bounteous.com post means.
One hunch I came up with is that the post is talking about sites that have actually made their own version of the UA script (i.e. modified analytics.js- I have not done this). Is that it?
You could use Global Site Tag for Google Ads conversion tracking without changing your current GA tracking setup at this point in time (though you would want to look at updating, once you have had a chance to check what needs to be ported over from Universal syntax to Global Site Tag).
If you were to only use gtag.js for google ads it would be similar to the following:
<!-- Global Site Tag (gtag.js) - Google AdWords: GOOGLE_CONVERSION_ID -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-GOOGLE_CONVERSION_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-GOOGLE_CONVERSION_ID');
</script>
If you were to combine the GA and Google Ads tracking the snippet would be along the following line
<script async src="https://www.googletagmanager.com/gtag/js?id=GA-PROPERTY_ID">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA-PROPERTY_ID');
gtag('config', 'AW-GOOGLE_CONVERSION_ID');
</script>
Custom dimensions would need to be mapped in the GA config command
https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
You would also need to update any event tracking to the gtag.js syntax, and same would apply to things like ecommerce tracking and so forth.
There is an analytics.js to gtag.js migration guide available
https://developers.google.com/analytics/devguides/collection/gtagjs/migration
I want to test whether a variant of my current homepage will perform better (reach a certain goal defined on GA), but I'm struggling to find a good solution.
Let's say the current version (Original) has sections A, B, C in that order. The other version (Variant), though, has sections in the order B, C, A. Note: the top navigation menu (linking to each section's anchor) must reflect this change.
I first considered Client-Side Experiments, which I have done in the past, but I'm worried those wouldn't look good when rendering the site: depending on loading speed, a Variant user would first see section A, and then they would see section A vanish (into the bottom of the page), while they could also notice the menu being changed.
I then considered the regular Experiment mode on Analytics, which asks me to determine two URLs to compare: the Original is my root path (e.g. http://mywebsite.xyz/) and the Variant would be something like http://mywebsite.xyz/home. But I can't orientate half of my users to this different URL - I want to test people who reach my homepage from wherever they may come.
I tried something through the Google Cloud App Engine: publishing two versions of my application, and splitting traffic 50/50 between both (cookie-based). When visiting the root path, one renders the Original, while the other renders the Variant version. Great. It works! But now Google Analytics has no idea which version it's tracking...
What I did: when the page first loads, I send an event with the version identifier as parameter, such as
ga('send', 'event', 'AB_Test', 'A');
// or
ga('send', 'event', 'AB_Test', 'B');
I suppose these would help me check the Events Flow and determine which version reaches more Event goals, but it's still not linked to an Experiment or its features.
Is there any better way to implement this? Am I missing something? It feels too complicated to do something that both the Cloud App Engine and the Analytics should help me achieve. (Thanks for reading, I know it's a huge text)
When I run this type of experiment, I typically try to leverage the API to determine the variation in the backend and then render the template appropriately.
For your current workaround, rather than sending events, I'd recommend instantiating the test on each server and manually setting the variant for each. See code below:
<!-- App 1 / Original -->
<script type="text/javascript" src="//www.google-analytics.com/cx/api.js?experiment=<EXPERIMENT ID>"></script>
<script type="text/javascript">
(function () {
cxApi.setChosenVariation(0);
}());
</script>
<!-- App 2 / Variant -->
<script type="text/javascript" src="//www.google-analytics.com/cx/api.js?experiment=<EXPERIMENT ID>"></script>
<script type="text/javascript">
(function () {
cxApi.setChosenVariation(1);
}());
</script>
I have this widget code that i wish to track via GA analytics without changing the code structure. how can i do this using GA event tracking feature.
the widget code is as below:
<script src="http://widgets.unnamed.co.ke/21/index.php?source=mysite" type="text/javascript"></script>
We've added google analytics code to the widget javascript. Note that you need to make some adjustments when the GA code is inside a function in your code. e.g:
var g = window._gaq || (window._gaq = []);
g.push(['some_unique_name._setAccount', 'UA-XXXXXXX-X']);
In addition you have to make sure your GA doesn't interfere with the site's GA. So you need to make sure that the domain (and some other definitions) is set to the same domain as the site's GA definitions. You also should make sure to use your own tracker.
we have a website with our application running in an iFrame on multiple domains and subdomains. The main website (www.example.com) has only static content with links to the sites with framed application sites. So sub.example.com, sub2.example.com, search.another.com have all iFrame with the application running.
We'd like to track all these sites with Google Analytics (GA). Subdomain tracking is working fine but I couldn't find a way to make the cross domain work accurately. The main issue is I cannot share the visitor cookie information among the top level domains. So, the same visitor who goes to sub.example.com and search.another.com get 2 different cookies, which result in various issues. (e.g. inflated visitor counter, cannot correctly track referral info, etc)
Can you please help me fix this?
(I've done a pretty thorough search on the web, tried several scenarios but no luck so far)
Here is the core of our GA implementation:
on sub.example.com (and all subdomains of the main website)
_gaq.push(['b._setAccount', 'UA-XXX']);
_gaq.push(['b._setDomainName', 'example.com']);
_gaq.push(['b._setAllowLinker', true]);
_gaq.push(['b._addIgnoredRef', 'example.com']);
_gaq.push(['b._addIgnoredRef', 'search.another.com']);
_gaq.push(['b._trackPageview']);
on search.another.com (all external subdomains have variants)
_gaq.push(['b._setAccount', 'UA-XXX']);
_gaq.push(['b._setDomainName', 'search.another.com']);
_gaq.push(['b._setAllowLinker', true]);
_gaq.push(['b._addIgnoredRef', 'example.com']);
_gaq.push(['b._addIgnoredRef', 'search.another.com']);
_gaq.push(['b._trackPageview']);
just after iframe on all pages
<script type="text/javascript">
_gaq.push(function ()
{
var iFrameTracker = _gat._getTrackerByName('b');
var iframe = document.getElementById('myframe');
iframe.src = iFrameTracker._getLinkerUrl(iframe.src);
});
</script>
on the link on www.example.com
<a href="http://search.another.com" onClick="_gaq.push(function ()
{
var tracker = _gat._getTrackerByName('b');
var linkerUrl = tracker._getLinkerUrl('http://search.another.com');
});">
linkerUrl has the correct Url with the cookie of www.example.com. But for some weird reason, GA assigns a new cookie on the search.another.com. I tried setting the domain name to none (['b._setDomainName', 'none']), which didn't help. I'm not sure if I'm missing a simple fundamental point here. I guess the issue might be related to having cross domain iFrames and the links can be either in the iFrame or in the frameset. So I want to track both.
I do the debugging with the Chrome GA Debugger addon.
(Btw, theoretically we can have infinite number of top-level / sub domains. So manually creating filters for each domain on GA is not an option. )
You're simply assigning the linkerUrl to a variable. You need to redirect the user to that url instead.
You should return false on the onClick handler to keep the browser from doing the usual redirect.
<a href="http://search.another.com" onClick="_gaq.push(function ()
{
var tracker = _gat._getTrackerByName('b');
var linkerUrl = tracker._getLinkerUrl('http://search.another.com');
window.location.href = linkerUrl;
});return false;">
Alternatively you should be using _link. Which does pretty much the same thing.
<a href="http://search.another.com"
onClick="_gaq.push(['b._link', this.href]);return false;">
I have been using Urchin 6 but have just started to use Google Analytics also. I am also using Google Search Appliance for site search.
Search is on a subdomain i.e. www.search.mysite.com
The problem is that Google Analytics is tracking site search as a self-referral. After a lot of reading online I have ended up with the GA code configuration below which should be picking up the search subdomain but it isn’t. Can anyone see anything incorrect about my configuration?
- E.g. is the GATC request process order correct
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-1']);
_gaq.push(['_setLocalRemoteServerMode']);
_gaq.push(['_setLocalGifPath', '/__utm.gif']);
_gaq.push(['_setDomainName', 'mysite.com]);
_gaq.push(['_addIgnoredRef', 'mysite.com']);
_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>
I have a suspicion that the issue could lie with the configuration of GA on Google Search Appliance. When you add GA it just asks for the UA code on the XSLT and you send up with the script below on each search page:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><script type="text/javascript">
<!--
_uacct = "UA-xxxxxxx-1";
urchinTracker();
//--></script>
Could this be the problem or does this code need to change in the XSLT or maybe not?
Any help would be appreciated.
Thanks
I don't have a complete answer for you, as I'm trying to work out some glitches myself. But maybe this will help suggest approaches.
I'm using version 6.8.0.G.30 of the search appliance.
I can insert my Google Analytics account number in the Analytics Account field under the "Global Attributes" section of the Page Layout Helper for the desired Appliance Front End.
That GUI approach has the effect of inserting the account number into the XSLT for that Front End:
<!-- *** analytics information *** -->
<xsl:variable name="analytics_account">UA-1234567-1</xsl:variable>
When the transformation is processed and the page is rendered, if a value is found for the account, then this JavaScript is generated in the search results page:
<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script><script type="text/javascript">
var pageTracker = _gat._getTracker("UA-1234567-1");
pageTracker._trackPageview();
</script>
As an alternative to using the Page Layout Helper, you can "Edit underlying XSLT code" to manually edit the stylesheet and insert the analytics account.
The Google Analytics code produced by the default XSLT may not be what you want (probably isn't based on your post). For example, the snippet above is the synchronous version.
So, you'll probably want to edit the XSLT anyway to modify the snippet. I wanted to use the asynchronous snippet, so I changed the template named "analytics" used in the XSLT (that specifies to not customize):
<!-- **********************************************************************
Analytics script (do not customize)
********************************************************************** -->
<xsl:template name="analytics">
<xsl:if test="string-length($analytics_account) != 0">
<script type="text/javascript" src="{$analytics_script_url}"></script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("<xsl:value-of select='$analytics_account'/>");
pageTracker._trackPageview();
</script>
</xsl:if>
</xsl:template>
That template is where the account information you've previously entered in the XSLT (via GUI or XSLT) gets substituted in. It's called at various locations in the Front End XSLT.
It's also possible to change the URL for the analytics script (you see that variable used in the "analytics" template).
What I did was to substitute the "analytics" template above with my own asynchronous version. So now when I look at the rendered search results, I see the async snippet there.
In my _setDomainName method, I have a leading period before the domain: .mysite.com which is consistent with the other Google Analytics-enabled pages on the rest of our site.
The "best practice" for this seems to be an area of some discussion: http://www.roirevolution.com/blog/2011/01/google_analytics_subdomain_tracking.php
Many of the comments on that post refer to self-referrals.
On the appliance search results page, the Google Analytics snippet appears immediately following the <body> tag.
The discussion of where to locate the asynchronous snippet (or "parts" if it's being split) has been raised in repeated forum posts:
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=71ba44443f0bfbc3&hl=en
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=22ac794d8f26a2f4&hl=en
This has been a pretty good reference for me on the asynchronous snippet:
Asynchronous Tracking Usage Guide:
http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html
Moving the snippet to <head> would take me some thinking and a more thorough look at the XSLT (and probably tweaking that would be jeopardized with future appliance versions and potential XSLT changes)
In terms of debugging Analytics, I've started to focus on investigating the values of GA-specific cookies and the __utm.gif using Firebug and other similar browser tools.
This post:
http://blog.vkistudios.com/index.cfm/2008/12/17/Slicing-and-Dicing-Cookies--Part-2--Body-Parts
as well as its followup, and other pages at that site have really helped suggest an approach to troubleshooting.