Copied to clipboard

Flag this post as spam?

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


  • Michal Koblasa 45 posts 139 karma points
    Oct 07, 2015 @ 16:10
    Michal Koblasa
    0

    User tracking - filter events

    Hello bros,

    i need to track user activity in the way of: date + ip + url + some other data. Becaose of datamining (yes we are using Google Analytics, but we need to do more custom tasks).

    Question: Which event i should use? I found EndRequest and LogRequest these events handles every request (including images, api calls etc.). Regarding to this thread it is becaose of local IIS http://forums.asp.net/t/1027556.aspx?HttpModule+s+BeginRequest+event

    Example for logged urls:

    /umbraco/RestServices/ScheduledPublish/Index
    /Docs/image.jpg 
    /umbraco/ping.aspx
    ...all request made by browser (around 40 for one page load )
    

    So i need to do stuff like this to get rid of this mess:

    if (!url.EndsWith(".js") &&
         !url.EndsWith(".css") &&
         !url.EndsWith(".jpg") && 
         ...etc...
         !url.EndsWith(".aspx") &&
         !url.Contains("_browserLink"))
    {
        UserLogService.AddActivity(GetIPAddress(), url);
    }
    

    But isnt there any better way? Any other event i should use or better way to filter request?

    Becaose there will be long list of stuff tu exclude from log. What about performance? I know these operations for filtering are fast, but still...

    Thank you for your ideas and hints. M.

  • Michal Koblasa 45 posts 139 karma points
    Oct 26, 2015 @ 10:16
    Michal Koblasa
    0

    Hello, if someone need my solution - im using this code:

    var url = Current.Request.Url.LocalPath.ToString();
    if (!url.EndsWith(".js") &&
         !url.EndsWith(".css") &&
         !url.EndsWith(".jpg") && 
         !url.EndsWith(".png") && 
         !url.EndsWith(".ttf") &&
         !url.EndsWith(".woff") &&
         !url.EndsWith(".svg") &&
         !url.EndsWith(".aspx") &&
         !url.EndsWith(".html") &&
         !url.EndsWith(".ashx") &&
         !url.EndsWith(".axd") &&
         !url.Contains("app_plugins") &&
         !url.Contains("App_Plugins") &&
         !url.Contains("umbraco") &&
         !url.Contains("_browserLink"))
    {
         UserLogService.AddActivity(IPAddresHelper.GetIPAddress(), url);
    }
    
  • Mangirish Wagle 34 posts 106 karma points
    Jun 22, 2016 @ 09:17
    Mangirish Wagle
    0

    But where are you pasting this code?

  • Michal Koblasa 45 posts 139 karma points
    Jun 30, 2016 @ 08:39
    Michal Koblasa
    0

    Hello, Im using this code in ApplicationEventHandler as follows:

    public class EventLogUser : ApplicationEventHandler { private Stopwatch stopwatch;

        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            UmbracoApplicationBase.ApplicationInit += UmbracoApplicationBase_ApplicationInit;  
        }
    
        /// <summary>
        /// Bind to the events of the HttpApplication
        /// </summary>
        void UmbracoApplicationBase_ApplicationInit(object sender, EventArgs e)
        {
            var app = (HttpApplication)sender;
            //Good for performance tests
            //app.EndRequest += umbracoApplication_EndRequest;
            app.BeginRequest += app_BeginRequest;
            app.PostAuthorizeRequest += umbracoApplication_EndRequest;
        }
    
        void app_BeginRequest(object sender, EventArgs e)
        {
            stopwatch = new Stopwatch();
            stopwatch.Start();
        }
    
        void umbracoApplication_EndRequest(object sender, EventArgs e)
        {            
            var url = HttpContext.Current.Request.Url.LocalPath.ToString();
            if (!url.EndsWith(".js") &&
                !url.EndsWith(".css") &&
                !url.EndsWith(".jpg") &&
                !url.EndsWith(".ico") &&
                !url.EndsWith(".png") && 
                !url.EndsWith(".ttf") &&
                !url.EndsWith(".woff") &&
                !url.EndsWith(".svg") &&
                !url.EndsWith(".aspx") &&
                !url.EndsWith(".html") &&
                !url.EndsWith(".ashx") &&
                !url.EndsWith(".axd") &&
                !url.Contains("app_plugins") &&
                !url.Contains("App_Plugins") &&
                !url.Contains("bundles") &&
                !url.Contains("umbraco") &&
                !url.Contains("_browserLink"))
            {
                stopwatch.Stop();
    
                UserLogService.AddActivity(IPAddresHelper.GetIPAddress(), url, stopwatch.ElapsedMilliseconds,"");
            }
        }
    }
    

    Hope this helps you. M.

Please Sign in or register to post replies

Write your reply to:

Draft