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.
- Open Widgets in the sidebar, under Engage.
- Click your widget. A new widget must be saved first.
- 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 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.
| Property | Description |
|---|---|
| widget | The URL of the widget. You find it on the widget's Implementation tab in the dashboard. Required. |
| widgetStyle | CSS rules to modify or fine-tune the position of the widget. Styling docs |
| catchClick | Element selector to catch clicks and open the widget. |
| floatWidget | Set true if the widget is a Float widget. |
| embedWidget | Set true if the widget is an Embed widget. |
| user | User properties (for user tracking). |
| data | Segmentation data. |
| lang | Language selector. |
| boosters | Set false to disable boosters on the page. Default: true. |
| onWidgetOpen | Called when the widget is opened. |
| onWidgetClose | Called when the widget is closed. |
| onWidgetResize | Called when the widget is resized. |
| onWidgetUnread | Called when the unread post count of the widget has been updated. |
Resources
Please follow our GitHub repo for further updates.
- https://github.com/announcekitapp/announcekit-vue
- https://www.npmjs.com/package/announcekit-vue
- https://codesandbox.io/s/announcekit-vue20-demo-jcfjf
Sample projects with an Embed, a Popup and a Modal widget:
- Embed widget sample: https://codesandbox.io/s/announcekit-vue-embed-sample-n5hrhr
- Popup widget sample: https://codesandbox.io/s/announcekit-vue-popup-sample-m04msj
- Modal widget sample: https://codesandbox.io/s/announcekit-vue-modal-sample-o0c15o