trying to implement a google analytics razor macro.. in my root node I have the properties googleTrackingEnabled as a true/false.. and googleTrackingAccountID..
I'm having issues getting my script to load: Error loading Razor Script GoogleAnalytics.cshtml
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'googleTrackingEnabled'
am I supposed to be checking for null even on the variable assignment?!
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ var useAnalytics = @Model.AncestorsOrSelf().googleTrackingEnabled; }
if(!string.IsNullOrEmpty(@useAnalytics.ToString()) && @useAnalytics)
{
@{ var googleTrackingAccountID = @Model.AncestorsOrSelf().googleTrackingAccountID; }
@if(!string.IsNullOrEmpty(@googleTrackingAccountID.ToString()))
{
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '@googleTrackingAccountID']);
_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>
}
}
Analytics Razor Macro
Hi Guys,
trying to implement a google analytics razor macro.. in my root node I have the properties googleTrackingEnabled as a true/false.. and googleTrackingAccountID..
I'm having issues getting my script to load: Error loading Razor Script GoogleAnalytics.cshtml
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'googleTrackingEnabled'
am I supposed to be checking for null even on the variable assignment?!
Hi Tom,
AncestorsOrSelf() returns a DynamicNodeList, that's why you get the error, if your property is on the root node, you should use
(Deleted the 's' from Ancestors)
which look up the variable on the node specified on the level passed as parameter.
Hope this helps.
Regards,
/Dirk
is working on a reply...