Try this:
Instead of the
<%= ((PageBase)Page).GetAnalyticsTrackingScript(Context) %>
like the instruction says, add this line near the end body tag:
<EPiServer:RequiredClientResources RenderingArea="Footer" ID="RequiredResourcesFooter" runat="server" />
Any idea about how to solve this in an MVC-site?
Using the following code gives me the same problem with the GA-script rendered without enclosing script-tags:
@Html.AnalyticsTrackingScript(Model.CurrentPage)
/Martin
Hi,
you can get almost working version by adding the following sections to your _layout.html file:
@Html.Raw(Html.RequiredClientResources("Header")) Somewhere just before HEAD closing tag
@Html.Raw(Html.RequiredClientResources("Footer")) Just before BODY closing tag.
When you have these in place and GA add-on installed and enabled, EPiServer will automatically inject code to both sections and tracking starts to work. There seems to BUT in this case also: the add-on tries to be clear and add tracking for downloads and other click events also (if so configured) but looks like there is a bug in this. EPiServer injects the js that contains function epiGat to the footer section and then the following code to header section:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-51567001-1']);
_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);
})();
if(window.epiGat)epiGat({"downloads":true,"extensions":"7z|aac|arc|arj|asf|avi|bin|csv|docx?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|png|pptx?|qtm?|ra(m|r)?|tar|tgz|txt|wav|wma|wmv|wpd|xlsx?|xml|z|zip","external":true,"mailto":true});
the last if statement will not be executed as this script is loaded before the script that contains the function to be called :(
@Janne Responded to your ticket in DevSupport. Just letting the thread know that this is a known bug submitted to product team for investigation. It seems like download, mailto, and external link traffic events don't get successfully recorded and likely related to the malform script you raised.
Just to confirm that we also have the problem with download, mailto, and external link traffic events not showing up in analytics after updating to the latest Google Analytics add-on.
Thanks Mikael, we have a known bug report for the download/mailto/external link issue.
We have installed the latest Google Analytics tracking script on one of our dev sites. After attaching the Tracking ID, we render the script as described at the bottom of http://webhelp.episerver.com/addons/googleanalytics/7.0/EN/Default.htm#GoogleAnalytics/Admins_GoogleAnalyticsSettings.htm%3FTocPath%3D_____2. However, when looking at what is returned by EPiServer.GoogleAnalytics.Extensions.GetAnalyticsTrackingScript((PageBase)this.Page, this.Context) we get the following:
<script src="/WebResource.axd?d=RPUHk73y4MwgxGGANRg3P7KRI5c4n85qgyDYGf6sCw0aK4kYMgfon-tcjyB-zh_cRnCKGvn1YA8Mwg-NlLYN0aUZCQGM4e_gfBRiWUCfSJqcyr3V_XqRyej8xPWJomacaCTs6EdRI_1cpvT4s6c4WKaoorBijRm4SFf_G6LEDwz7zi6trP0C3ECL3iIx4pmC0&t=635126911211066203" type="text/javascript"></script> var _gaq = _gaq || [];
_gaq.push(['_setAccount', '*TRACKING_ID_FROM_ADMIN_MODE']);
(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);
})();
_gaq.push(['_setCustomVar', 1, 'Page', '4']);
_gaq.push(['_setCustomVar', 2, 'Lang', 'en']);
_gaq.push(['_trackPageview']);
if(window.epiGat)epiGat({"downloads":true,"extensions":"7z|aac|arc|arj|asf|avi|bin|csv|docx?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|png|pptx?|qtm?|ra(m|r)?|tar|tgz|txt|wav|wma|wmv|wpd|xlsx?|xml|z|zip","external":true,"mailto":true});
(*TRACKING_ID_FROM_ADMIN_MODE being the account info we set)
Notice how the actual GA script stuff is not wrapped in script tags. This renders as plain text in the browser. Is this a bug or are we missing something?