Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • junto 7 posts 28 karma points
    May 06, 2010 @ 13:23
    junto
    0

    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

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    May 06, 2010 @ 13:30
    Lee Kelleher
    1

    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:

    <umbraco:Item field="javascriptAnalytics" recursive="true" runat="server" />

    You can then include the Google Analytics code on a per-site basis.

    Cheers, Lee.

  • junto 7 posts 28 karma points
    May 06, 2010 @ 18:26
    junto
    0

    Does that mean that all of the other document types should inherit from the Home document type for that to work?

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    May 06, 2010 @ 18:31
    Lee Kelleher
    0

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

  • junto 7 posts 28 karma points
    May 06, 2010 @ 18:48
    junto
    1

    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.

  • Lee Kelleher 4022 posts 15810 karma points MVP 13x admin c-trib
    May 06, 2010 @ 21:39
    Lee Kelleher
    0

    You're welcome, glad it worked out! Don't forget to mark the solution.

    Thanks, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft