1 /**
  2  * @fileoverview Basic metrics capability.  Expectation is that new metrics will 
  3  *  likely be set up as separate files / separate sets.    
  4  */
  5 
  6 /**
  7  * @namespace
  8  */
  9 var Ozone = Ozone || {};
 10 
 11 /**
 12  * @namespace
 13  */
 14 Ozone.metrics = Ozone.metrics || {};
 15 
 16 /**
 17  * @description Basic logging capability - meant to be called by other methods
 18  *    which transform or validate data  
 19  * @since OWF 3.8.0
 20  *
 21  * @param {String} userId
 22  * @param {String} userName
 23  * @param {String} metricSite Identifier, potentially URL, for source of metric - typically OWF instance
 24  * @param {String} componentName    
 25  * @param {String} componentId 
 26  * @param {String} componentInstanceId
 27  * @param {String} metricTypeId String describing metric - recommend package name construct
 28  * @param {String} metricData Any additional data for metric - do any necessary validation appropriate to metricTypeId before sending through 
 29  */
 30 Ozone.metrics.logMetric = function(userId, userName, metricSite, componentName, componentId, componentInstanceId, metricTypeId, metricData) {
 31 	var currentDate = new Date();
 32 	
 33     Ozone.util.Transport.send({
 34         url: OWF.getContainerUrl() + '/metric',
 35         method: 'POST',
 36         onSuccess: function(response) {
 37         },
 38         autoSendVersion : false,
 39         content : {
 40           metricTime: currentDate.getTime(),
 41           userId: userId,
 42           userName: userName,
 43           site: metricSite,
 44           userAgent: navigator.userAgent,
 45           component: componentName,
 46           componentId: componentId,
 47           instanceId: componentInstanceId,
 48           metricTypeId: metricTypeId,
 49           widgetData: metricData
 50         }
 51     });
 52 };
 53 
 54 /**
 55  * @description Logs a set of metrics to the server all at once.  All
 56  * metrics passed into a call to this function will be logged in a single
 57  * HTTP request, instead of one request per metric
 58  * @since OWF 6.0
 59  *
 60  * @param {Array} metrics 
 61  * @param {String} metrics[*].userId
 62  * @param {String} metrics[*].userName
 63  * @param {Number} metrics[*].metricTime The time at which is metric was collected (in UNIX time)
 64  * @param {String} metrics[*].site Identifier, potentially URL, for source of metric - typically OWF instance
 65  * @param {String} metrics[*].component
 66  * @param {String} metrics[*].componentId 
 67  * @param {String} metrics[*].instanceId
 68  * @param {String} metrics[*].metricTypeId String describing metric - recommend package name construct
 69  * @param {String} metrics[*].widgetData Any additional data for metric - do any necessary validation appropriate to metricTypeId before sending through 
 70  * @param {String} metrics[*].userAgent Should be set to the user-agent string of the browser
 71  */
 72 Ozone.metrics.logBatchMetrics = function(metrics) {
 73 	var currentDate = new Date();
 74 	
 75     Ozone.util.Transport.send({
 76         url: OWF.getContainerUrl() + '/metric',
 77         method: 'POST',
 78         onSuccess: function(response) {
 79         },
 80         autoSendVersion : false,
 81         content : {
 82         	data: metrics
 83         }
 84     });
 85 };
 86 
 87 /**
 88  * @description Log view of widget - see calls in dashboards
 89  * @since OWF 3.8.0
 90  *
 91  * @param {String} userId     - see Ozone.metrics.logMetric userId
 92  * @param {String} userName   - see Ozone.metrics.logMetric userName
 93  * @param {String} metricSite - see Ozone.metrics.logMetric metricSite
 94  * @param {Object} widget   
 95  */ 
 96 Ozone.metrics.logWidgetRender = function(userId, userName, metricSite, widget) {
 97 
 98   // checking here, on the assumption we may save ourselves some validation time
 99   //   on any widget data validation (last param)
100   if (Ozone.config.metric.enabled === true) {
101       Ozone.metrics.logMetric(userId, userName, metricSite, widget.name, widget.widgetGuid, widget.id, "ozone.widget.view", "");
102       }
103 };
104