We try to set up google experiments to work with our backend setup and found that there is API for letting GA know what variation we have selected to show for the user through function:
cxApi.setChosenVariation(chosenVariation, opt_experimentId);
When I visit official docs: https://developers.google.com/analytics/devguides/collection/gajs/experiments
it says that:
"ga.js is a legacy library. If you are starting a new implementation we recommend you use the latest version of this library, analytics.js. For exisiting implementations, learn how to migrate from ga.js to analytics.js."
We do use analytics.js.
Does it mean that all the functions present in ga.js are already in analytics.js and we do not need to worry about using this function?
You can try the browser-only Implementation as explained at https://developers.google.com/analytics/devguides/collection/analyticsjs/experiments. Instead of ga.js or analytics.js, you can try gtag.js. Visit https://developers.google.com/analytics/devguides/collection/gtagjs/migration to learn how to migrate from analytics.js to gtag.js. I am sharing the code below of how I implemented my experiment. Remember to create the experiment in Google Analytics, you will find it in the BEHAVIOR > Experiments section. In the code below, you will need to use your own Experiment ID.
<head>
.......................................
.......................................
.......................................
<!-- Load the Content Experiment JavaScript API client for the experiment -->
<script src="//www.google-analytics.com/cx/api.js?experiment=MY_EXPERIMENT_ID"></script>
<script>
// Ask Google Analytics which variation to show the user.
var chosenVariation = cxApi.chooseVariation();
// Define JavaScript for each page variation of this experiment.
// Wait for the DOM to load, then execute the view for the chosen variation.
$(document).ready(function(){
switch (chosenVariation) {
case 0:
// Original: Do nothing. This will render the default HTML.
break;
case 1:
//document.getElementsByClassName('logo_tagline')[0].value = 'I love programming';
$(".logo_tagline:first").text("I love programming");
break;
case 2:
//document.getElementsByClassName('logo_tagline')[0].value = 'Programming is my passion';
$(".logo_tagline:first").text("Programming is my passion");
break;
case 3:
//document.getElementsByClassName('logo_tagline')[0].value = 'I enjoy writing code';
$(".logo_tagline:first").text("I enjoy writing code");
}
});
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
</head>
Related
Hi i'm new to vaadin and i have a problem implementing google analytics with vaadin.
I have searched a lot in forums and I have not been able to find the solution.
I would like someone with experience in this process to guide me to connect vaadin with google analytics.
I have already created a Google Analytics account and it has generated a JS for me:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Y3YPVNQBCZ"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-Y3YPVNQBCZ');
</script>
My problem now is that in the google analytics Tracker plugin (https://vaadin.com/directory/component/googleanalyticstracker/samples) it does not specify how to add the JS code and I don't know what else to look for, please help !!
I need a little guide because I don't know where to start working
(SOLVED)
There is a component you can use:
https://vaadin.com/directory/component/googleanalyticstracker/samples
You can use an annotation
https://github.com/samie/vaadin-ga-tracker/blob/master/demo/src/main/java/org/vaadin/googleanalytics/tracking/demo/MainLayout.java
Like:
#EnableGoogleAnalytics(value = "G-Y3YPVNQBCZ")
I have started to develop my first Typo3-Website.
To track interactions I have included Google Analytics with the following-code in the Setup-Section of the main-template:
page.headerData.9000 = TEXT
page.headerData.9000.value(
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-04738GHDL1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-04738GHDL1', { 'anonymize_ip': true });
</script>
)
With Google Tag Manager-plugin I am able to verify, that a global-site-tag is sent to my G-04738GHDL1 tag
But I am not able to see anything in Google Analytics. Account and property is selected correctly.
Any ideas?
You don't need to anonymize the IP, it is a parameter not foreseen in GA4 since anonymization is always active.
So try replacing this:
gtag('config', 'G-04738GHDL1', { 'anonymize_ip': true });
with this:
gtag('config', 'G-04738GHDL1');
If the TypoScript Object page.headerData.9000 is not overwritten somewhere else in your TypoScript it should work fine. You can check the TypoScript Object Browser in the Template module for that.
Set up correctly, the code should be output in your site's HTML.
From there I would suggest having a look at your browser's inspector tools, checking the console tab for any errors (e.g. regarding JavaScript errors or any CSP violations) and the network tab whether any request towards google are sent.
If you aren't familiar with that, the Google Chrome browser extension Tag Assistant is quite helpful. ;)
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've just started using GA (after I took a long vacation from it). It seems I'm missing something obvious/simple here.
I don't understand why in my analytics account / admin / property / tracking code they tell me to put this into <header> :
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-blahblah-1');
</script>
While in their docs they tell me to use this:
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
Src: https://developers.google.com/analytics/devguides/collection/analyticsjs/#the_javascript_tracking_snippet
These are completely different scripts o.O Additionally, the examples here https://developers.google.com/analytics/devguides/collection/analyticsjs/how-analyticsjs-works just don't work with the first snippet, because ga is undefined.
Is this because they have different API versions? Then... why isn't this explained somewhere o.O
I'm asking because I get
unreachable code after return statement
In the console, on this javascript: https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code-1:formatted
I also found this answer:
Why is tracking code generated for my site different than what is in the documentation?
But it's from 2015, and the js snippets are again different, so I guess I can't use it as a reference.
All of this is just weird, this is why there are so many "o.O" in my question, please forgive me :)
This is definitely slightly confusing, but you're seeing the difference between analytics.js and gtag.js. You can learn more about the differences between them and/or migrating to gtag.js here.
Hope this helps!
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.