Example Javascript and Ruby on Rails applications for track and store user navigation flow.
This is a exemple project to show how to store user web navigation actions. It was made in the simplyest way possible. An API that receives data from a webpage using a Javascript file that in fact stores the user information. Each different or private browser instance is treated as a single user. For the sake of simplicity it was not implemented any authentication nor velidation controls.
This project contais 2 main apps.
- App (1) Is an Ruby on Rails API. This API is responsible for store the contact's email and all the pages that was accessed by him.
- App (2) Is an couple of static web pages that uses an Javascript library that keeps track of users navigation.
Requirements:
- Ruby version 2.3
- Rails version 5
- html5 compatible browser
- postgresql database
After repository is cloned you should enter in the rdappAPI folder:
$ cd rdappAPIThen configure the database file in:
$ ./rdappAPI/config/database.ymlYou should create 2 databases in postgres (one for development data and another for test). After that, you have to provide username, password and database name for development and test enviroments in database.yml file.
Go to the root API folder 'rdappAPI':
execute the database migration:
$ rake db:migrateand start the rails server:
$ rails sYour API is ready to receive data, and will be accessible at: http://localhost:3000/
To start a exemple of website that uses track lib you should go to the clientSite folder:
$ cd ./rdapp/clientSiteNow you can start a simple ruby server mimicing clients webserver:
$ ruby -run -ehttpd . -p8000Client pages will be accessible at
http://localhost:8000/home.html,
http://localhost:8000/sobre.html,
http://localhost:8000/preco.html,
http://localhost:8000/contato.html
For test the API in the rdappAPI folder run:
$ rails testTo get an list of all contacts, access the API at:
http://localhost:3000/contatosTo get an specific contact and the list of pages associated to him, access API at:
http://localhost:3000/contatos/{contato_id}API:
https://morning-sands-43096.herokuapp.com/contatos #lists all contacts
https://morning-sands-43096.herokuapp.com/contatos/{contato_id} #lists specific contact and his pages