Try our conversational search powered by Generative AI!

Tracking Script Weirdness with Google Analytics plug-in


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  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') + '';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
_gaq.push(['_setCustomVar', 1, 'Page', '4']);
_gaq.push(['_setCustomVar', 2, 'Lang', 'en']);


(*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?

Aug 29, 2013 21:53

I have this exact same problem.

Sep 02, 2013 9:17

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" />

Sep 03, 2013 13:47

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:




May 12, 2014 14:27


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']);
(function () {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

the last if statement will not be executed as this script is loaded before the script that contains the function to be called :(

Jun 23, 2014 14:08

@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.

Jun 25, 2014 0:41

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.

Jun 27, 2014 14:57

Thanks Mikael,  we have a known bug report for the download/mailto/external link issue.

Jun 27, 2014 20:54
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.