diff --git a/lib/WebGUI/PassiveAnalytics/Logging.pm b/lib/WebGUI/PassiveAnalytics/Logging.pm new file mode 100644 index 000000000..26f5bd3d8 --- /dev/null +++ b/lib/WebGUI/PassiveAnalytics/Logging.pm @@ -0,0 +1,47 @@ +package WebGUI::PassiveAnalytics::Logging; + +use strict; +use WebGUI::Session; +use WebGUI::Asset; + +=head1 NAME + +Package WebGUI::PassiveAnalytics::Logging + +=head1 DESCRIPTION + +Encapsulate all logging functions in here. + +=cut + +#---------------------------------------------------------------------------- + +=head2 log ( session, asset ) + +Log Passive Analytics data to the db. + +=head3 session + +A session variable. + +=head3 asset + +The asset to log. + +=cut + +sub log { + my ($session, $asset) = @_; + return unless $session->setting->get('passiveAnalyticsEnabled'); + my $assetClass = $asset->get('className'); + $assetClass =~ s/^WebGUI::Asset:://; + if ( $assetClass ne 'Snippet' + && substr($assetClass,0,4) ne 'File') { + $session->db->write( + q|INSERT INTO `passiveLog` (userId, sessionId, assetId, timestamp, url) VALUES (?,?,?,?,?)|, + [ $session->user->userId, $session->getId, $asset->getId, time(), $session->request->unparsed_uri,] + ); + } +} + +1;