VueJS Component

Dealing with externally loaded libraries in JavaScript apps is a little bit tricky. You need to load the script manually, wait until it's loaded, get the library variable, and so on. You can also include the <script> in your main HTML file, but this is not quite a good solution.

Knowing all this boring stuff, we have created a VueJS component that helps you include an AnnounceKit widget in your app.

Step 1: Install the component

Install the component from npm:

npm install --save announcekit-vue

Step 2: Get your widget's URL

Before adding the component to your VueJS app, you need the URL of the widget you want to include. You find it in the widget's JavaScript code, as the widget key.

  1. Open Widgets in the sidebar, under Engage.
  2. Click your widget. A new widget must be saved first.
  3. Open the Implementation tab and look at the Javascript box.

In the code below, the widget URL is https://changelog.announcekit.app/widgets/v2/3739N6.

The Javascript code on a widget's Implementation tab, with the widget URL on the line that starts with widget

The examples below use the widget https://announcekit.app/widgets/v2/31nbbO. Replace it with yours.

Step 3: Add the component to your app

First, register the plugin in your main.js:

import { createApp } from "vue";
import App from "./App.vue";
import AnnounceKit from "announcekit-vue";

const app = createApp(App);
app.use(AnnounceKit);
app.mount("#app");

Using Vue 2? Install announcekit-vue@2 and register it locally instead: import AnnounceKit from 'announcekit-vue'; export default { components: { AnnounceKit } }

Then use the component in your template:

<template>
  <nav>
    <ul>
      <li>
        <a href="/home">Home</a>
      </li>
      <li>
        <a href="/product">Product</a>
      </li>
      <li>
        <a href="#" class="ak-trigger">News</a>
        <AnnounceKit
          catchClick=".ak-trigger"
          widget="https://announcekit.app/widgets/v2/31nbbO" />
      </li>
    </ul>
  </nav>
</template>

As you see, we set the catchClick property on the component. It listens for a click on the element you name, and a click on that element opens the widget. This property is not mandatory, but it is most useful with the Badge and Line launchers. That's all!

Properties

Here is the list of properties the component accepts. Some of them are very useful.

PropertyDescription
widgetThe URL of the widget. You find it on the widget's Implementation tab in the dashboard. Required.
widgetStyleCSS rules to modify or fine-tune the position of the widget. Styling docs
catchClickElement selector to catch clicks and open the widget.
floatWidgetSet true if the widget is a Float widget.
embedWidgetSet true if the widget is an Embed widget.
userUser properties (for user tracking).
dataSegmentation data.
langLanguage selector.
boostersSet false to disable boosters on the page. Default: true.
onWidgetOpenCalled when the widget is opened.
onWidgetCloseCalled when the widget is closed.
onWidgetResizeCalled when the widget is resized.
onWidgetUnreadCalled when the unread post count of the widget has been updated.

Resources

Please follow our GitHub repo for further updates.

Sample projects with an Embed, a Popup and a Modal widget:

Was this helpful?