Shared Master, multiple sites, different Google Analytics codes
I have a number of sites setup but using a single Master template. In that template I currently have the GA code, but the tracker code is hard coded.
What would be the best way to make this dynamic, based on the site hostname?
Or am I barking up the wrong tree here and I need to create different templates? Problem is that all of the other templates use that master, and I don't fancy duplicating the lot!
I've used this approach on several sites now, it works a treat.
In your homepage document-type, create a new property with the alias "javascriptAnalytics" using the "Textbox multiple" data-type. Then in the bottom of your master template, add this tag:
No. It means that the template will check if a property called "javascriptAnalytics" exists, if not, then it goes up a parent/level and checks there, until it reaches the homepage node. (The "recursive" param enables this).
Shared Master, multiple sites, different Google Analytics codes
I have a number of sites setup but using a single Master template. In that template I currently have the GA code, but the tracker code is hard coded.
What would be the best way to make this dynamic, based on the site hostname?
Or am I barking up the wrong tree here and I need to create different templates? Problem is that all of the other templates use that master, and I don't fancy duplicating the lot!
Regards
Junto
Hi Junto,
I've used this approach on several sites now, it works a treat.
In your homepage document-type, create a new property with the alias "javascriptAnalytics" using the "Textbox multiple" data-type. Then in the bottom of your master template, add this tag:
You can then include the Google Analytics code on a per-site basis.
Cheers, Lee.
Does that mean that all of the other document types should inherit from the Home document type for that to work?
No. It means that the template will check if a property called "javascriptAnalytics" exists, if not, then it goes up a parent/level and checks there, until it reaches the homepage node. (The "recursive" param enables this).
I just tried that out. Awesome.
I've now used it for Google Maps script call as well so that I can change the API key.
Great suggestion. Thank you for the rapid answers.
You're welcome, glad it worked out! Don't forget to mark the solution.
Thanks, Lee.
is working on a reply...