UNPKG

@mobiloud/ml-qr-widget

Version:
199 lines (135 loc) β€’ 9.15 kB
[![Version](https://img.shields.io/badge/npm-1.2.0-red?link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40mobiloud%2Fml-qr-widget)](https://www.npmjs.com/package/@mobiloud/ml-qr-widget) [![Static Badge](https://img.shields.io/badge/MobiLoud-%23047857?link=https%3A%2F%2Fwww.mobiloud.com%2F)](https://www.mobiloud.com/) # MobiLoud QR Widget Promoting your app to desktop users to drive more app installs is also a great option, for this we recommend using our own QR Code Widget. The QR Code Widget allows you to promote app-specific features, and discounts, followed by a QR code that can be scanned to open your app install page on mobile devices. ## **What Are QR Widgets?** QR widgets are modals/popups that show up when someone lands on your mobile website, prompting them to get your app. Here's an example: ![qr-app-widgets.png](./qrExample.png) ## Features ML QR Widget features: - Configuration options: - Widget position - Widget delay - Texts fonts - Texts color - Widget BG - QR colors - QR with images - Text content - Entering animation - Display options: On load or when user scrolls up/down - Fallback App Icon option --> If the provided icon link is invalid / or image can not be displayed, an icon is generated using the App Name Param and Button colors - Default options set (if not texts, images or colors provided, it shows placeholder info, useful for catching errors or for testing while implementing the widgets) - Widget can be used as a module or used directly in an html / script tag - Code written in Typescript and minified/bundled with Vite ## πŸ“– How to use QR Widget can be used importing the JS code via CDN or as a module using NPM ### πŸš€ With CDN In order to install the QR Code Widget you will want to add the following piece of code into your website, between the <head></head> tags: ```javascript <script type="module" src="https://cdn.jsdelivr.net/npm/@mobiloud/ml-qr-widget/dist/ml-qr-widget.min.js"></script> <script> function addQrWidget() { new QrWidget().init(); } window.addEventListener('load', addQrWidget); </script> ``` ## Configuration options: ```javascript const options = { fontFamily: `"Source Sans Pro", "Arial", sans-serif`, // (string) Font family for widgets texts, defaults to system safe fonts textColor: '#222', // (string) Widget texts color (any color property value) textHeading: 'Get 10% OFF using MobiLoud app', // (string) Heading Text textDescription: 'Scan our QR to download the app on your device and unlock the discount', // (string) Description text widgetsColor: '#fff', // (string) Widget BG color backDrop: true,// (boolean) if true, adds a backdop in front of the page backDropZIndex: 888888, // (number) z-index of the backdrop, should be lower than widgets z-index qrOptions: { // Params for the QR Generation, ues params from this docs: https://quickchart.io/documentation/qr-codes/ text: 'https://redirect.mobiloud.com/?ios=https://itunes.apple.com/&android=https://play.google.com', size: 150, margin: 0 }, qrAlt: 'QR code to download our mobile app', // (string) Alt text for the QR position: 'center', // (string) Position of the widgets, default 'center'. 'center' | 'top-right' | 'top-left' | 'bottom-left' | 'bottom-right' animation: 'fadeIn', // (string) Widget animation, default 'fadeIn'. 'fadeIn' | 'scaleUp' | 'slideBottom' | 'slideTop' | 'slideLeft' | 'slideRight' | null, display: 'onLoad', // (string) Display options, default 'onLoad'. 'onLoad' | 'onScrollDown' | 'onScrollUp' radius: '10px', // (string) Widget radius with CSS units delay: 0, // (number) defines how much time to wait until the element shows up shadow: true, // (boolean) If true applies soft shadow, true | false useSession: false, // (boolean) If true, after widgets is closed, it creates a session registry to hide widgets on page reloads until the end of user's session zindex: 999999, // (number) Widget z-index maxWidth: "400px", // (string) Max Width of the widgets with CSS units sessionExpire: 1440 // (number) time for banner to show again in minutes starting from the time the banner is shown, defualt: 1440 (1 day) }; const qrWidget = new QrWidget(options); ``` ## Methods ```javascript deviceData.os // returns current os "android" | "ios" | "windows" | "desktop" deviceData.isCanvas // returns true or false deviceData.isMobile // returns true or false ``` ## Recipes This are useful ways to implement the widget. We always recommend using an Event Listener to trigger the code when the document is loaded `window.addEventListener('load', fnName)` ### Insert QR Banner on desktop only ```javascript function addQrWidget() { if(deviceData.isMobile || deviceData.isCanvas ){ return } new QrWidget(options).init(); } window.addEventListener('load', addQrWidget); ``` ### Using deviceData method to filter devices ```javascript const options = { // Set params here } // Insert widgets only in our Canvas platform if(deviceData.isCanvas) { const qrWidget = new QrWidget(options).init(); } // Apply specific configs based on OS if(deviceData.os === "android" || deviceData.os === "windows") { const qrWidget = new QrWidget(options1).init(); } if(deviceData.os === "desktop" || deviceData.os === "ios") { const qrWidget = new QrWidget(options2).init(); } // Insert widgets only in Mobile userAgent if(deviceData.isMobile) { const qrWidget = new QrWidget(options3).init(); } ``` ## Redirect URL We have a custom URL For redirecting users to the correct store with only one link. For doing it, you can use this Link: https://redirect.mobiloud.com/ this accepts 2 parameters: `?ios` , `?android`. This parameters should contain a url for each of the stores, when the user opens the redirect link on their phone, it will take them to the correct store like so: `https://redirect.mobiloud.com/?android=https://linkToPlaystore.com&ios=https://linkToAppStore.com` ## Development - `npm run build` produces a production version into /dist folder - `npm run dev` runs dev version and starts a dev server ## Testing the QR widgets You will definitely want to test the QR widgetss once you deploy them to your website, to make sure that everything works and looks as you want. Running these tests on real mobile devices can get overwhelming, so we recommend that you run your tests on your desktop browser. To do this, you will need to emulate a mobile device by adjusting your [browser’s user agent](https://developer.mozilla.org/en-US/docs/Glossary/User_agent). We recommend using the following Chrome extension to do this: [User Agent Switcher and Manager](https://chrome.google.com/webstore/detail/user-agent-switcher-and-m/bhchdcejhohfmigjafbampogmaanbfkg) Once you have installed the extension, set it up as follows: ### **Step 1** Select β€œChrome” as the browser and β€œAndroid” as the platform if you want to test the Android version of the widgets, or β€œSafari” and β€œiOS” in case you want to test the iOS version: ![annotely_image (61).png](https://mobiloud.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F3c66d89a-b74e-441a-a15f-197d08f78807%2Fannotely_image_(61).png?table=block&id=7b5f225a-60e2-4001-bcdb-e4627b300be4&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2) ### **Step 2** Select one of the options that will appear, any will work: ![annotely_image (62).png](https://mobiloud.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fdec5d36c-69ec-40f5-aaf9-d4cc54e1e972%2Fannotely_image_(62).png?table=block&id=dd116c73-51a6-449f-b34c-03358baadb92&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2) ### **Step 3** Click β€œApply” to make sure the user agent is properly set up on your browser: ![annotely_image (63).png](https://mobiloud.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fcb126a7c-e078-4250-889c-83653ce496dd%2Fannotely_image_(63).png?table=block&id=eae2261a-b36c-43b3-b151-2c02fc4ac39a&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2) ### Step 4 You can now press β€œF5” while viewing your website to refresh the browser window with the updated user agent. ### Reset If you want to revert the changes to the user agent, as some websites might start behaving differently after doing so, you can click the β€œReset” button: ![annotely_image (64).png](https://mobiloud.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F8af461b2-d9a7-43bf-9d0a-bec281b98347%2Fannotely_image_(64).png?table=block&id=9e9c3806-30d7-495e-820c-bfca7d0e8331&spaceId=f1cb51a8-e748-4832-9335-2c96a2e81d09&width=1230&userId=&cache=v2) ## License Copyright (c) MobiLoud