Programadores

JavaScript API

Control the Messenger from your own code.

After the snippet loads, call Shopxare(command, …) from your page.

boot

Starts the Messenger. app_id is required.

Shopxare('boot', {
  app_id: 'YOUR_APP_ID',
  user_id: '42',            // your own ID for a logged-in user
  user_hash: 'HMAC…',       // see Identity verification
  email: '[email protected]',
  name: 'Ada Lovelace',
  phone: '+48 600 000 000',
  attributes: { plan: 'pro', shop_orders: 3, shop_cart_items: 2, shop_cart_total: '59.90', shop_currency: 'EUR' },
  company: { company_id: '7', name: 'Analytical Ltd' },
  hide_default_launcher: false,
});

Shop data shows as a Shop card next to the conversation: shop_orders, shop_total_spent, shop_currency, shop_cart_items, shop_cart_total and shop_viewing_product (the WooCommerce plugin and the Shopify snippet send these for you).

Set hide_default_launcher: true to hide the round button and open the Messenger from your own button.

update

Send new user data, for example after login.

Shopxare('update', { email: '[email protected]' });

show, hide and showNewMessage

Shopxare('show');
Shopxare('hide');
Shopxare('showNewMessage');

trackEvent

Record something the customer did. Events appear on the contact and can start flows.

Shopxare('trackEvent', 'added_to_cart', { sku: 'A-100', price: 49 });

Listen for changes

Shopxare('onUnreadCountChange', (count) => { /* update your badge */ });
Shopxare('onShow', () => {});
Shopxare('onHide', () => {});

shutdown

Call this on logout. It ends the session, so the next person on the same browser does not see the conversations.

Shopxare('shutdown');

Ainda com dúvidas? Contacto