Copied to clipboard

Flag this post as spam?

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


  • DanielLeeUK 6 posts 26 karma points
    Aug 24, 2015 @ 15:53
    DanielLeeUK
    0

    404 Tracking in Analytics

    This is probably one of those easy fixes from a dev perspective but we need to track 404's and with the way umbraco deals with 404's (internally) it doesn't display a URL that can be used to track in analytics.

    Is there a way to add GA event tracking to all 404's within Umbraco, if so how and is dev effort required to implement.

    Really appreciate the help.

  • Ryan 9 posts 30 karma points
    Aug 24, 2015 @ 19:38
    Ryan
    0

    I was already tracking page views in my master template but your post you post made me revisit this.

    In my template after already initializing ga I added this. This assumes that you already have a 404 page configured in \config\umbracoSettings.config.

        @if (Context.Response.StatusCode == 200)
    {
    <script type="text/javascript">
        ga('send', 'pageview',
        {
            title: '@Html.Raw(HttpUtility.HtmlDecode(title).Replace("'", "\\'"))'
        });
    </script>
    }
    else if (Context.Response.StatusCode == 404)
    {
    <script type="text/javascript">
        ga('send', 'event', 'Page Not Found', '@Html.Raw(HttpUtility.HtmlDecode(Request.RawUrl).Replace("'", "\\'"))');
    </script>    
    }
    else if (Context.Response.StatusCode == 500)
    {
    <script type="text/javascript">
        ga('send', 'event', 'Error', '@Html.Raw(HttpUtility.HtmlDecode(title).Replace("'", "\\'"))');
    </script>
    }
    
  • DanielLeeUK 6 posts 26 karma points
    Sep 02, 2015 @ 16:35
    DanielLeeUK
    0

    Thanks Ryan, will give that a go. Will update you on how it goes.

    Appreciate the help.

  • Richard Soeteman 4051 posts 12924 karma points MVP 2x
    Sep 07, 2015 @ 13:58
    Richard Soeteman
    0

    I assume you want to track those url's to fix the broken link issues. You might want to check-out SEOChecker for that http://soetemansoftware.nl/seo-checker

    Best,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft