metricsHelper.prototype.sendAnonymousMetric = function()

in cloudformationTemplates/startChatContactAPI/js/metricsHelper.js [40:79]


    metricsHelper.prototype.sendAnonymousMetric = function(metric, cb) {

        let _options = {
            hostname: 'metrics.awssolutionsbuilder.com',
            port: 443,
            path: '/generic',
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            }
        };

        let request = https.request(_options, function(response) {
            // data is streamed in chunks from the server
            // so we have to handle the "data" event
            let buffer;
            let data;
            let route;

            response.on('data', function(chunk) {
                buffer += chunk;
            });

            response.on('end', function(err) {
                data = buffer;
                cb(null, data);
            });
        });

        if (metric) {
            request.write(JSON.stringify(metric));
        }

        request.end();

        request.on('error', (e) => {
            console.error(e);
            cb(['Error occurred when sending metric request.', JSON.stringify(_payload)].join(' '), null);
        });
    };