// After user logs in or data loadswindow.Asyntai = window.Asyntai || {};
window.Asyntai.userContext = {
"Customer name": currentUser.name,
"Email": currentUser.email,
"Subscription plan": currentUser.subscription.planName,
"Cart total": cart.total,
"Loyalty points": currentUser.loyaltyPoints
};
// You can update it anytime - changes apply to the next messagewindow.Asyntai.userContext["Cart total"] = newTotal;
チャットが開いたときにのみユーザーデータを取得します(パフォーマンスに最適):
// Define a function to fetch user contextwindow.Asyntai = window.Asyntai || {};
window.Asyntai.fetchUserContext = function() {
return fetch('/api/your-user-context-endpoint/')
.then(function(response) { return response.json(); })
.then(function(data) {
window.Asyntai.userContext = data;
});
};
// The widget automatically calls this when the chat opens