2018-08-05 20:31:33 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Delphi MVC Framework
|
|
|
|
//
|
2020-01-06 16:49:18 +01:00
|
|
|
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
|
2018-08-05 20:31:33 +02:00
|
|
|
//
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
//
|
|
|
|
// Based on an idea by Nirav Kaku (https://www.facebook.com/nirav.kaku)
|
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// *************************************************************************** }
|
|
|
|
|
|
|
|
unit MVCFramework.Middleware.Analytics;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
MVCFramework,
|
|
|
|
MVCFramework.Logger,
|
|
|
|
System.Classes,
|
|
|
|
LoggerPro;
|
|
|
|
|
|
|
|
type
|
|
|
|
TMVCAnalyticsMiddleware = class(TInterfacedObject, IMVCMiddleware)
|
|
|
|
private
|
2020-02-28 18:33:28 +01:00
|
|
|
fLogWriter: ILogWriter;
|
2018-08-05 20:31:33 +02:00
|
|
|
protected
|
|
|
|
procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
|
|
|
procedure OnAfterControllerAction(Context: TWebContext; const AActionNAme: string; const Handled: Boolean);
|
2020-02-28 18:33:28 +01:00
|
|
|
procedure OnBeforeControllerAction(Context: TWebContext; const AControllerQualifiedClassName: string;
|
|
|
|
const AActionNAme: string;
|
2018-08-05 20:31:33 +02:00
|
|
|
var Handled: Boolean);
|
2020-04-29 01:57:29 +02:00
|
|
|
procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
|
|
|
|
|
2018-08-05 20:31:33 +02:00
|
|
|
public
|
|
|
|
constructor Create(const ALogWriter: ILogWriter); virtual;
|
2020-02-28 18:33:28 +01:00
|
|
|
property LogWriter: ILogWriter read fLogWriter;
|
2018-08-05 20:31:33 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2019-10-30 00:21:13 +01:00
|
|
|
System.SysUtils, System.DateUtils;
|
2018-08-05 20:31:33 +02:00
|
|
|
|
|
|
|
{ TMVCAnalyticsMiddleware }
|
|
|
|
|
|
|
|
constructor TMVCAnalyticsMiddleware.Create(const ALogWriter: ILogWriter);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
2020-02-28 18:33:28 +01:00
|
|
|
fLogWriter := ALogWriter;
|
2018-08-05 20:31:33 +02:00
|
|
|
end;
|
|
|
|
|
2020-02-28 18:33:28 +01:00
|
|
|
procedure TMVCAnalyticsMiddleware.OnAfterControllerAction(Context: TWebContext; const AActionNAme: string;
|
|
|
|
const Handled: Boolean);
|
2018-08-05 20:31:33 +02:00
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
2020-04-29 01:57:29 +02:00
|
|
|
procedure TMVCAnalyticsMiddleware.OnAfterRouting(AContext: TWebContext; const AHandled: Boolean);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
2020-02-28 18:33:28 +01:00
|
|
|
procedure TMVCAnalyticsMiddleware.OnBeforeControllerAction(Context: TWebContext;
|
|
|
|
const AControllerQualifiedClassName, AActionNAme: string;
|
2018-08-05 20:31:33 +02:00
|
|
|
var Handled: Boolean);
|
|
|
|
begin
|
2020-02-28 18:33:28 +01:00
|
|
|
fLogWriter.Info(Context.Request.ClientIp + ';' + AControllerQualifiedClassName + ';' + AActionNAme + ';' +
|
|
|
|
Context.Request.RawWebRequest.Method + ';' + Context.Request.RawWebRequest.PathTranslated + ';' +
|
|
|
|
Context.Request.RawWebRequest.PathInfo
|
2018-08-05 20:31:33 +02:00
|
|
|
+ ';' + Context.Request.RawWebRequest.Referer + ';' + Context.Request.RawWebRequest.Host, 'analytics');
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMVCAnalyticsMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
// do nothing
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|