!function ($) { if (typeof lmd == 'undefined') { console.error('Adobe Chat Tracking is missing from the parent window'); return; } function isProactiveChat() { if (typeof insideChatPane === "undefined") return false; const currentVA = typeof insideChatPane.getCurrentWorkflow === "function" && insideChatPane.getCurrentWorkflow(); const isBot = currentVA && currentVA.isBot; return (insideChatPane.lastMessageFrom && insideChatPane.lastMessageFrom.search('assistant') > -1 && !insideChatPane.activeChat && !insideChatPane.chatEnded && !isBot); } function replaceGlobalObject() { window.lmd_temp = lmd; let newObject = { bu: lmd.bu, cc: lmd.cc, language: lmd.language, storeID: lmd.storeID, storeType: lmd.storeType, taxonomytype: lmd.taxonomytype, lenovoID: _insideGraph.current.visitorId, insideID: insideFrontInterface.chat.userid.split(':')[2], pageName: 'Chat Page', }; lmd = newObject; } function track(interaction) { //console.log('[Adobe Tracking]', interaction, lmd); _satellite.track(interaction); setTimeout(function () { lmd = window.lmd_temp; }, 1000); } function chatInitiation(type) { replaceGlobalObject(); lmd.Chat = type === 'reactive' ? 'Reactive chat Clicked' : 'proactive chat'; lmd.Conversationid = getConversationId(); lmd.Source = _insideGraph.jQuery('title').html().trim(); track('chat-initiation'); } function chatTypeSelection(type) { replaceGlobalObject(); lmd.chatType = type; lmd.Conversationid = getConversationId(); track('chat-type-selection'); } function getConversationId() { return insideFrontInterface.currentChatId || 0; } let chatType, contactType; function picklistOptionClicked(e) { if(insideChatPane.chatEnded) { insideFrontInterface.currentChatId = 0; } if ($(this).closest('.picklist').hasClass('custom-ui')) { // Main Menu if(contactType) { chatType = contactType + ' : ' + e.target.innerText; } else { chatType = e.target.innerText; } } else { chatType += ' : ' + e.target.innerText; } _insideGraph.defer(function () { chatTypeSelection(chatType); }, function () { return insideFrontInterface.currentChatId; }); } _insideGraph.defer(function () { const chatDocument = $(insideChatPane.frame.contentDocument); chatDocument .on('click', '.picklistOption', picklistOptionClicked) .on('click', '#endChatCancel', function () { chatTypeSelection('Close : No'); }); chatDocument.find('#endChatItem, #insideChatPaneCloseButton').click(function() { chatTypeSelection('Close'); }); }, function () { return typeof insideChatPane !== 'undefined' && insideChatPane.frame && insideChatPane.chatPane; }); _insideGraph.bind("googleAnalytics", function (event) { if (event.category === 'Inside : Chat Tab' && event.action === 'Clicked') { if(typeof insideChatPane !== 'undefined' && insideChatPane.chatEnded) { insideFrontInterface.currentChatId = 0; } chatInitiation('reactive'); } }); _insideGraph.bind("openchatv2", function () { if(typeof event !== 'undefined' && event.target) { if($(event.target).hasClass('insideContactUsLink') || $(event.target).closest('.insideContactUsLink').length) { contactType = location.href.search('/contact/sales-support') > -1 ? 'Sales' : 'Customer Care'; } } }); $.inside.bind("chat", function (messages) { const lastMessage = messages[messages.length - 1]; const fromWorkflowBot = lastMessage.metadata && lastMessage.metadata.fromWorkflowBot; insideChatPane.chatEnded = false; if (lastMessage.text == "/stopchat") { insideChatPane.chatEnded = true; } // triggered when Visitor received Proactive Chat _insideGraph.defer(function () { if (isProactiveChat() && lastMessage.fromid.startsWith('assistant:') && !fromWorkflowBot) { chatInitiation('proactive'); } }, function () { return typeof insideChatPane !== 'undefined' && insideChatPane.frame && insideChatPane.chatPane; }); }); _insideGraph.bind('chatended', function (data) { if(data.endedBy === 'visitor') { chatTypeSelection('Close : Yes'); } insideChatPane.chatEnded = true; }); }(_insideGraph.jQuery)