function mg_include(src, callback){ var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; if(callback) { var userAgent = navigator.userAgent.toLowerCase(); if(/msie/.test( userAgent ) && !/opera/.test( userAgent )) { script.onreadystatechange = function() { if(script.readyState == 'complete') callback(); } } else { script.onload = function () { callback(); } } } script.src = src; head.appendChild(script); } function MGApi(){ var is_load_mg_jq = true; if(typeof jQuery != "undefined") { var version_array = jQuery.fn.jquery.split("."); if(parseInt(version_array[0])>1 || (parseInt(version_array[0])==1 && parseInt(version_array[1])>=7)){ is_load_mg_jq = false; } } if(is_load_mg_jq){ mg_include("https://mailganer.com/static/mailguner/js/jquery.min.js", function(){}); } (function(r){window.r46=window.r46||function(){(r46.q=r46.q||[]).push(arguments)};var s=document.getElementsByTagName(r)[0],rs=document.createElement(r);rs.async=1;rs.src='//cdn.rees46.ru/v3.js';s.parentNode.insertBefore(rs,s);})('script'); r46('init', 'c1dcfad35e3f47d991a24ec06efd30'); console.log("track mg -- initial_code"); } MGApi.prototype.auth = function(mg_email){ //console.log("auth -- "+mg_email); if(mg_email){ r46('profile', 'set', {email: mg_email}); jQuery.ajax({ url: "https://mailganer.com/recommendations/check/email/1441/", dataType: "jsonp", crossDomain: true, data: {'email': mg_email}, success: function(result){ if(result.status == 'ok'){ console.log("track mg -- set_email " + mg_email); }else{ console.log(result.error); } }, error: function (responseData, textStatus, errorThrown) { console.log("Произошла ошибка на сервере. Попробуйте повторить ваш запрос через несколько минут!") } }) } } function sendResponse(data){ var url = "https://mailganer.com/track/1441/" jQuery.ajax({ url: url, dataType: "jsonp", crossDomain: true, data: data, success: function(result) { if (result.status == 'ok'){ //console.log("Track complete"); } else { console.log(result.error); } }, error: function (responseData, textStatus, errorThrown) { console.log("Произошла ошибка на сервере. Попробуйте повторить ваш запрос через несколько минут!") } }) } MGApi.prototype.track = function(action_type, params){ console.log("track mg -- "+action_type, params); var action_type_r46 = action_type; switch (action_type_r46) { case 'add_cart': action_type_r46 = 'cart'; break; case 'remove_cart': action_type_r46 = 'remove_from_cart'; break; case 'clear_cart': action_type_r46 = 'cart'; params = {}; break; } r46('track', action_type_r46, params); if(action_type === 'remove_cart'){ var product_id = params; params = {}; params['id'] = product_id; } if (action_type === 'purchase'){ params['products'] = JSON.stringify(params['products']); } if (action_type === 'search'){ var query = params params = {} params['query'] = query } if (action_type === 'category'){ var category_id = params params = {} params['category_id'] = category_id } params['track'] = action_type; sendResponse(params) } MGApi.prototype.subscribeTrigger = function(action_type, params){ console.log("subscribe trigger mg -- "+action_type, params); var action_type_r46 = action_type; switch (action_type_r46) { case 'product_stock': action_type_r46 = 'product_available'; break; case 'product_reduce_price': action_type_r46 = 'product_price_decrease'; break; } r46('subscribe_trigger', action_type_r46, params); } MGApi.prototype.searchProduct = function(query){ MGApi.prototype.track('search', query ) } MGApi.prototype.viewCategory = function (category_id) { MGApi.prototype.track('category', category_id) }