top of page

Tracking User Page Visits

ATTENTION: THIS IS OUR OLD SITE. TO SEE OUR NEW WEBSITE, CLICK HERE.

It is often useful to know and record which users are visiting which pages and when on your website. This code example shows you how to record and track your users page visits for later analysis, as is done for WixCodeBank.
The first step is to create a collection to store the page view history, similar to the screenshot below. Add the fields which are important for you to keep a history of. The created date field is automatically recorded and does not need to be added explicitly. The collection needs to allow anyone to update and add to it. This example creates a collection called ViewHist for saving historical page view information.
Lines Of Code
For this example, a page view is recorded every time a user visits a dynamic item page in the WixCodeBank (as you are doing now). The following code creates a function to insert data into the ViewHist table from the dbCustomer and dbCodeBank datasets of the dbCodeBank dynamic item page. If the current user is not logged in, then the emailAddress inserted into ViewHist is set to 'Unknown', else the users email address is inserted from dbCustomer. Title and item number are other data points inserted from dbCodeBank. The saveViews() function can be called anywhere on your dynamic item page to trigger a view save, and is best used with a time delay to ensure it is not an accidental page visit, e.g.: setTimeout(saveViews,3000);
Lines Of Code
Lines Of Code
Lines Of Code
Lines Of Code
Unlock
Please login or sign-up (it's free!) to view our code. Refresh the page if already logged in.
Disclaimer: To the best of our knowledge, this code works for its stipulated purpose. If you find an error in our code, or know of a better way to achieve the same result - please contact us! We will help where we can, however please be aware that the code is provided 'as is' and without a promise of support in using or implementing it.
bottom of page