add google Analytics code

Topics: Administration, Core, General
Mar 27, 2012 at 10:08 AM

hi,

I want to add the google analytics code for all the pages in my website without using a widget.

I try to add the code in the file : layout.cshtml in the themes folder below the references for style and script files, and in the website its appeared within the body tags.

Where I need to add the code that will be between the head tags?

thanks

Developer
Mar 27, 2012 at 12:05 PM

Add it in Document.cshtml :

Copy it from Orchard.Web\Core\Shapes\Views and paste it in Themes\YourTheme\Views

Mar 11, 2014 at 8:27 PM
Edited Mar 11, 2014 at 8:27 PM
I'm also attempting to do this - add in GA code to website on Orchard, but without installing a module or widget. I don't see a document.cshtml file, and on layout.chtml I don't see where I should add the code. From what I understand, the GA code needs to go right before </head>

Can anyone help?
Mar 12, 2014 at 8:58 AM
If your theme doesn't have a custom document.cshtml, it uses the default one in the folder agriffard posted. You can copy that file to your theme's views folder to override and add your script there.

Alternatively, you can add the following block to Layout.cshtml.
@using (Script.Head()) {
    <script language="javascript" type="text/javascript">
        //your script here
    </script>
}
Jan 1, 2015 at 5:24 PM
Can you please simplify this for me, I'm used to working in WordPress and not familiar with this CMS. Where should I go to find document/layout.chtml? And once I edit that file, will the GA code be above the closing head tag?
Jan 2, 2015 at 6:20 AM
find this file in your sistem :
Orchard.Web\Core\Shapes\Views\document.cshtml
and copy it to folder Themes\YourTheme\Views

then you can edit the new file as you wish.

thx
juna
Developer
Jan 2, 2015 at 4:14 PM
Or you could just add the code to an Html widget (it won't display anything if you don't want to) or use one of the Google Analytics modules.
Developer
Jan 2, 2015 at 4:44 PM
Yes. Or even better: a Shape widget(using a Template to define the shape).