Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database storage #730

Open
LarryBarker opened this issue Sep 10, 2019 · 3 comments
Open

Database storage #730

LarryBarker opened this issue Sep 10, 2019 · 3 comments

Comments

@LarryBarker
Copy link

I'm surprised no one has mentioned this already, or if they have, I was unable to find it. Anyhow, has anyone stored tour state in a database before? If so, how is this possible? I know there will be requirements on the backend, but I am more interested in knowing how to set it up on the frontend. Any help or advice is greatly appreciated! Thank you :)

@IGreatlyDislikeJavascript

You could do this by adding code to getstate and setstate functions to make an ajax call to your back end. It's easy enough to do that, but handling exceptions will be more challenging e.g. If back end is unavailable, doesn't respond quickly enough etc.

This is,a really unique requirement so probably not one I'm going to look into, sorry!

@LarryBarker
Copy link
Author

LarryBarker commented Oct 11, 2019

@IGreatlyDislikeJavascript Thanks for the reply. Aside from tracking tours in a database, how does one go about tracking the tour for users in general? For example, if a user starts/stops a tour on one device, or session, and revisits the site from a new device or session, surely they don't want to be prompted with the tour everytime, right? Obviously I assume the user is signed in to the application/site.

@IGreatlyDislikeJavascript

@LArbearrr personally I've just ignored this issue! My tour trigger is related to a "first login" to a system which is also an "initial setup" page. So quite simply, I just use PHP on the backend to include or not include the .js depending on initialSetupDone == true or false.

I actually think your question isn't a Tour question at all - it's a question about tracking front end activities in the back end system. So for me I'd solve this mostly outside of Tour.

Assuming you have a unique UserID available at the front end in your site's .js code, I would simply use $.getJSON or similar to grab the tour status from the backend, and $.ajax to POST the tour status to the backend after a tour completes etc.

You can retrieve the current tour step or whether the tour has ended either from Tour itself, or from localstorage. I'd simply use that to control the tour status per login.

So here's my hacked up pseudo code solution.

mysite.com/backend.php:

if(isset($_GET["current tour step"]))
{
    $result = database::sql("select last_tour_step from tourstatus where userid = ". $_GET["userid"]);
    echo json_encode($result);
}

if($_SERVER['REQUEST_METHOD'] == "POST" && isset($_GET["update the tour step"]))
{
    database::sql("update my table set last_tour_step to ". $_POST["last step this user was on"] ."where userid = ". $_POST["userid"]);
}

Then in mysite.com/somepage.html for the front end:

var myTour = new Tour({
onEnd: function(tour)
                {
                        var last-tour-step = myTour.getCurrentStepIndex(); // IMPORTANT SEE BELOW
                        var tourEnded = myTour.ended();
                        $.ajax(
                            dataType: json,
                            url: "mysite.com/backend.php?update-the-tour-step,
                            data: {
                                        lastTourStepThisUserWasOn: last-tour-step,
                                        tourWasEnded: tourEnded
                                    }
                        );
                },
....all your other options....
});

$( document ).ready(function()
{
    $.getJSON("http://mysite.com/backend.php?get_current_tour_step", { userID: whatever }, function(jsonDataResponse)
        {
                var last-tour-step = jsonDataResponse.last_tour_step;
                // update Tour step here by Tour obj
                myTour.setCurrentStep(last-tour-step);

                // OR! Just set it straight in localstorage and reload the tour

                myTour.start();
        });
});

FYI I've created a fork called Bootstrap Tourist which is a drop-in replacement for Tour and fixes a lot of issues and adds a lot of features, because the creators of original Tour in this repo don't have the time to maintain it any more. Suggest that if you'd like to look into this more, you can open a feature request in my repo.

IMPORTANT: my Bootstrap Tourist fork has additional funcs e.g.: getCurrentStepIndex() that aren't in original tour, so you'll need to check your code. Also, simply instantiating Tour will cause it to do stuff, so you may need to handle that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants