1.0.9 • Published 4 years ago

aploze-js v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Aploze.js

npm version

(https://aploze.github.io/aploze-js/)

Introduction

This document describes how to install and use Aploze’s browser-side JavaScript library, Aploze.js.

Including Aploze.js

Include the Aploze.js script between <head> tag in each page of your site. It should always be loaded directly from https://js.aploze.com/, rather than included in a bundle or hosted yourself.

<head>
  <script type="text/javascript" src="https://js.aploze.com/v1.js"></script>
</head>
<body>
  ...
</body>

Using Aploze.js as a module

We also provide an npm package that makes it easier to load and use Aploze.js as a module :

npm install aploze-js

Usage

Aploze init

// Init
Aploze.init({
  key: "your-key",
});

// Listen
Aploze.on("ready", (datas) => {
  // Aploze Library is ready !! 🎉
  // log account relative datas (domain, events etc...)
  console.log(datas);
});

Aploze will automatically create a <div id="aploze-player"></div> and fill it with the player overlay. The player overlay is where all your Aploze events are shown.

(See all Initialization Options.)

(See all Listenable JS events.)

Open the player overlay

To see your Aploze events UI in prelive, live or replay status, you need to open the player overlay with an Aploze event ID.

Aploze.player.open("your-event-id");

(See all Available JS methods.)

You can access to your Aploze events IDs in the "ready" JS event handler.

Aploze.on("ready", (datas) => {
  // Aploze Library is ready !! 🎉

  // Log all my Aploze events
  console.log(datas.events);

  // Loop all my Aploze events, and create a button for each one,
  // to open them in the player overlay

  for (var event of datas.events) {
    var $event = document.createElement("button");

    // Set the event title as button label
    $event.textContent = event.title;

    // Attach click listener to open the player with the right event ID
    $event.addEventListener("click", function () {
      Aploze.player.open(event.id);
    });

    // Append my button to body
    document.body.appendChild($event);
  }
});

Cart Integration (Optional)

For a better user experience, users can access to the shopping cart and add products directly from the Aploze player interface. To do this, you need to :

  • Redirect the user to your cart page when the cart button is clicked, for this, pass the url on init :
// Init
Aploze.init({
  key: "your-key",
  cart_url: "https://yourshop.com/cart...",
});

(See all Initialization Options.)

  • Listen 'player.add_to_cart' JS Event to be notified when a product is added to the cart by user and return the callback function to notify the user on the player interface.

(See all Listenable JS events.)

Aploze.on("player.add_to_cart", function (product, callback) {
  yourAddToCartMethod(product.id)
    .then(() => {
      callback(true); // item successfully added to your cart
    })
    .catch((error) => {
      if (error.type === "out-of-stock") {
        // Unsuccessful due to 'out of stock'
        callback({
          success: false,
          error: "out-of-stock",
        });
      } else {
        // Unsuccessful due to other issues
        callback(false);
      }
    });
});

Reference

Available JS methods

Here all methods you can use :

MethodParamsDescription
Aploze.init(options)options: ObjectInitialize Aploze.js (See all initialization options)
Aploze.player.open(event_id?, options?)event_id: StringOpen the player with current Aploze Event or new one if event_id is set. options = {status: 'live'} to simulate the Live Status
options: ObjectIn options, you can simulate the Aploze Event Live Status: {status: 'live'}
Aploze.player.close()Close the player
Aploze.player.reduce()Reduce the player

Initialization Options

Here are some of the most commonly used options:

KeyValid typesDefault ValueAvailable valuesDescription
keyStringRequired. The Aploze access key as a string
debugBooleanfalseSet to true to display debugging information
links_targetString_blank_blank, _selfHow Aploze player links are opened. _self create an iframe on the current page for internal links. (⚠️ for security errors, see Troubleshooting)
cart_urlStringYour Cart page url

Listenable JS Events

Here are all listenable JS events:

Event NameHandler paramsDescription
ready(datas)Aploze.js is ready to be used
error(error)Aploze.js has an error
player.event_startPlayer is instancied with an Aploze Event ID
player.event_status(status)The current Aploze Event in the player has changed (prelive, live, replay)
player.add_to_cart(product, callback)User click on the "Add to cart" button. Don't forget to return the callback
player.go_to_cartUser click on the "Go to Cart" button
player.openPlayer is opened
player.closePlayer is closed
player.reducePlayer is reduced
player.expandPlayer is expanded
player.dragReduced Player is dragged
player.dragstartReduced Player has started to by dragged
player.dragendReduced Player has finished to by dragged

Troubleshooting

Security Issues with iFrame :

  • X-Frame-Options = DENY (RFC7034)

    Possible solution: Set X-Frame-Options = SAMEORIGIN

  • Content-Security-Policy: frame-ancestors 'none'; (CSP level 2)

    Possible solution: Content-Security-Policy: frame-ancestors 'self';

FAQ

Does the cart integration works with product variants?

Yes, if each combinations of variants has a unique ID, you can deal with multi-variants products.

Help

If you have any technical issue, question or request, please contact us: tech@aploze.com

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1-security

4 years ago