Javascript SDK v2

Send data to Movalio from your website via Javascript.

Installation

Insert the following script in the <head> section for all pages of your website. To get your code snippet:

  • Sign in to your Movalio account
  • Navigate to Integrations > Movalio API
  • Copy the embed script snippet

The code snippet looks like this:

<script async src="https://cdn.movalioapp.com/sdk-v2/app.js"></script>
<script>
window.Movalio = window.Movalio || []; function movalio(){ Movalio.push(arguments) }
movalio('config', { app_id: APP_ID, domain: 'DOMAIN' });
</script>

APP_ID and DOMAIN are specific for your account and application. You can get them from the Movalio API integration.

Web Push Channel Only

If you are using the web push notifications channel you need to create a file named sw.js in the root of your site with the following content:

importScripts('https://cdn.movalioapp.com/sdk-v2/sw.js');

If you are not able to create the file directly inside the public root of your website, create it inside a subdirectory. In this case you need to specify the path in the config section.

...
movalio('config', { app_id: APP_ID, domain: 'DOMAIN', path: 'some/subdir/' });
....

You can register callback functions to be notified when certain events happen. Add them to the config object.

...
movalio('config', {
  app_id: APP_ID,
  domain: DOMAIN,

  onWidgetsReady: function() {
    // widgets are initialized and you can call specific widget functions
  },

  ...

});
...

This is the full list of callback functions you can use:

  • onWidgetsReady
  • onSubscribed
  • onAlreadySubscribed
  • onPromptAccept
  • onPromptReject
  • onPromptShow
  • onPromptIgnore
  • onSoftPromptAccept
  • onSoftPromptReject
  • onSoftPromptIgnore
  • onSoftPromptShow

Working with tags

Tags are properties associated to subscribers.

In order to add or update a tag for the subscriber use the following syntax:

movalio('tag', 'tag_name', 'optional_tag_value');

You can add or update multiple tags at once as instructed below:

movalio('tag', { tag_name_1: value_1, tag_name_2: value_2, ... });

Set tag value must to null if you want to add multiple tags without values.

Remove a tag like this:

movalio('removeTag', 'tag_name');

Sending events

Events are actions associated to subscribers.

const data = { key_1: value_1, key_2: value_2 }; //optional event data
movalio('event', 'event_name', data);

If you want to assign a certain value to an event include a key named value with a numeric value for the event. Event values can later be used in conversion reports.

For example:

movalio('event', 'purchased_subscription', { value: 199 });

For E-commerce there is a special type of event, a product event.

const data = { key_1: value_1, key_2: value_2 }; //optional event data
movalio('event', 'product:viewed_product', {
  product_id,
  variant_id,
  title,
  link
});

You can send an event when a subscriber:

  • views a product: product:viewed_product
  • adds a product to cart: product:added_to_cart
  • orders a product: product:ordered_product

Send shopping cart

Use the following syntax to send shopping cart content.

movalio('cart', {
  items: [
    {
      id: 100 // your product id
      variant_id: 1001 // if it's a variant of the main product
      title: 'Product title',
      link: 'https://product_link',
      price: '$20',
      quantity: 3,
      totalPrice: '$60',
      image: 'https://product_image',
    },
    ...
  ],
  totalPrice: '$190',
  itemCount: 5, // total items in cart
  uniqueItemCount: 3 // total unique items in cart
});

Working with widgets

Here is the syntax to call widget functions from within your code:

movalio('widget', widget_id, functionName, params);

When you are 100% sure that widgets have been loaded (e.g. inside onWidgetsReady callback) you can use these syntax:

Movalio.widget(widget_id).functionName(params);

Embeding a sign up form

You can embed a signup form widget on any page of your website. Create them from your Movalio account, Widgets section.

Here’s how the embed code will look like:

<script id=_movalio_1634804079275>movalio('widget', 7, 'showEmbed', ['_movalio_1634804079275'])</script>