AI OnAI Off
Hi!
Do you mean how to inject the GA-script on the pages? I'd guess the most common way to do this would be to modify the masterpage to include the script, but there are numerous other methods, for example to register it programmatically using a pageplugin attached to an appropriate Page-event.
Regards,
Johan
Hi
I usually do this from code so that I can check if in edit mode and if so not render the script... Like this:
// Register GA script
if (!InEditMode)
{
HtmlGenericControl objControl = new HtmlGenericControl("script");
objControl.Attributes.Add("type", "text/javascript");
objControl.InnerHtml = "var _gaq = _gaq || []; _gaq.push(['_setAccount', 'your_key']); _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); })();";
Page.Header.Controls.Add(objControl);
}
I think the best way is to make a dynamic property called Add2Header, and output that value in the head section of the masterpage.
This way the editor can change the script, or add new ones, without any stress
Very nice suggestion Anders. Looks like a very good approach.
I'll research dynamic property then.
How do you normally implement GA in EPiServer? What's the most efficient way of doing it?