UNPKG

apisearch-interactions

Version:

Interactions logger for apisearch Machine Learning.

41 lines (39 loc) 1.27 kB
/** * _asi (api search interactions) can be anything or an array * at this point, if it is an array, we can collect all data inserted previously * and perform given track actions once the object is created * * _asi.push([app_id, token_id, user_id, item_id, item_type, weight]) * _asi.push(['4378437', '3434-3432-432', '12345', '1', 'product', 10]) * * @returns {{push: push}} * @private */ const _asi = function() { return { /** * Push interaction * @param t */ push: function(t) { let lastChild = document.body.lastChild, element = document.createElement('img'), interaction = { user: {'id': t[2]}, item_uuid: {id: t[3], type: t[4]}, weight: t[5] }; element.src = 'http://localhost:8999/v1/interact' + '?app_id=' + t[0] + '&token=' + t[1] + '&interaction=' + JSON.stringify(interaction) ; element.height = 1; element.width = 1; element.style.display = 'none'; lastChild.parentNode.insertBefore(element, lastChild); } } }; module.exports = _asi();