This guide provides a method to update visitor information using the Olark API if you have an AngularJS app. The method allows you to add a visitor’s name and email to a chat conversation.

In this example, $rootScope.user.email is a way to check if the user is logged in to the particular application before setting the Olark values. I also set a local variable called $rootScope.olarkSet to true, so that it will only send once to the Olark JavaScript API.

angular.module('myApp',[]).
run(function($rootScope, user, $location, $http) {

    user.init({ appId: 'abc123' });

    $rootScope.$on("$routeChangeStart", function () {

        if ($rootScope.user.email && !$rootScope.olarkSet) {
            olark('api.visitor.updateEmailAddress', {emailAddress: $rootScope.user.email
        });

        olark('api.visitor.updateFullName', {
            fullName: $rootScope.user.first_name + ' ' + $rootScope.user.last_name
        });

        $rootScope.olarkSet = true;

    }

});
});