Giter Club home page Giter Club logo

appcues-arcadier's Introduction

AppCues-Arcadier

Understanding this requires in-depth knowledge and experience of Arcadier's APIs, Arcadier's Developer Resources, and Appcues Developer Resources

This plugin allows your AppCues account to be connected to your Arcadier marketplace. After setting up your your account on Appcues, the JS script of this plugin will send the user GUID of the logged in user to AppCues's backend and display the correct flow specified by you.

Source code running on Admin Portal: None.

Source code running on Buyer/Seller pages: user -> scripts -> scripts.js

How it works

Line 3 in scripts.js is what identifies allows Arcadier to identify you AppCues account.

As soon as the page is ready, the script appends the following script to the page head:

$(document).ready(function(){

    var appcues_script = document.createElement("script");
    appcues_script.src = "//fast.appcues.com/88888.js";  //this number is an identifier given to you by AppCues
    document.head.appendChild(appcues_script);

});

Next, the function Appcues.page(); needs to be run. This function is defined by the script added to the page previously.

Because of the sequence of loading of plugin scripts on Arcadier pages, Appcues.page(); needs to run strictly after all Arcadier's own scripts and page contents are loaded. So, it is made to run in a setInterval() function which runs only once.

5 seconds is chosen arbritrarily here to make sure everything has had time to load.

$(document).ready(function(){

    //include AppCues script in the page
    var appcues_script = document.createElement("script");
    appcues_script.src = "//fast.appcues.com/88888.js";
    document.head.appendChild(appcues_script);

    //start an interval that will only run 5 sec after the previous line is executed
    var interval = setInterval(function(){

        //initialises AppCues
        Appcues.page();

        //stops the setInterval
        clearInterval(interval);
    }, 5000);

});

Next, the identity of the current user needs to be identified and sent to AppCues, this is done by calling the User API:

$(document).ready(function(){

    //include AppCues script in the page
    var appcues_script = document.createElement("script");
    appcues_script.src = "//fast.appcues.com/88888.js";
    document.head.appendChild(appcues_script);

    //start an interval that will only run 5 sec after the previous line is executed
    var interval = setInterval(function(){

        //initialises AppCues
        Appcues.page();

        //get User GUID from the page HTML
        var userGuid = $("#userGuid").val();

        //get user authentication token from cookie
        var token = getCookie('webapitoken');
        
        //Arcadier API call
        var settings = {
            "url": "/api/v2/users/" + userGuid + "?includes=addresses&includes=UserLogins",
            "method": "GET",
            "headers": {
                "Authorization": "Bearer " + token
            }
        };

        $.ajax(settings).done(function(response){
            //handle API response to send to AppCues
        }

        //stops the setInterval
        clearInterval(interval);
    }, 5000);

    function getCookie(name){
        var value = '; ' + document.cookie;
        var parts = value.split('; ' + name + '=');
        if (parts.length === 2) {
            return parts.pop().split(';').shift();
        }
    }

});

Next the response from Arcadier API is parsed and the information required by AppCues is sent to AppCues using window.Appcues.identify()

$(document).ready(function(){

    //include AppCues script in the page
    var appcues_script = document.createElement("script");
    appcues_script.src = "//fast.appcues.com/88888.js";
    document.head.appendChild(appcues_script);

    //start an interval that will only run 5 sec after the previous line is executed
    var interval = setInterval(function(){

        //initialises AppCues
        Appcues.page();

        //get User GUID from the page HTML
        var userGuid = $("#userGuid").val();

        //get user authentication token from cookie
        var token = getCookie('webapitoken');
        
        //Arcadier API call
        var settings = {
            "url": "/api/v2/users/" + userGuid + "?includes=addresses&includes=UserLogins",
            "method": "GET",
            "headers": {
                "Authorization": "Bearer " + token
            }
        };

        $.ajax(settings).done(function(response){
            window.Appcues.identify(
                response.UserLogins[0].ProviderKey,
                {
                    email: response.Email,
                    firstName: response.FirstName,
                    lastName: response.LastName,
                    birthdate: response.DOB,
                    suburb: response.Addresses[0].City,  //Addresses[0] needs to be emphasized here because in case of many addresses, this line of code will only take the first address
                    state: response.Addresses[0].State
                }
            );
        });

        //stops the setInterval
        clearInterval(interval);
    }, 5000);

    function getCookie(name){
        var value = '; ' + document.cookie;
        var parts = value.split('; ' + name + '=');
        if (parts.length === 2) {
            return parts.pop().split(';').shift();
        }
    }

});

That's all the plugin needs to function.

Any futher customisation is done on AppCues's dashboard like:

  • Which user/groups of users see what content
  • Which page URL will trigger which AppCues flow

To test if AppCues was properly installed and connected to Arcadier, just add ?hey_appcues to any URL like so:

https://your-marketplace.sandbox.arcadier.io/user/marketplace/dashboard?hey_appcues

appcues-arcadier's People

Contributors

tanoojoy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.