I was wondering what would be the best way to go about storing/tracking user activity on a website. I am thinking of user activity along the lines of which webpage a user visited,how many times has she visited,when(i.e timestamp) of his/her vists.
我想知道在网站上存储/跟踪用户活动的最佳方式是什么。我考虑的是用户访问了哪个网页,访问了多少次,访问的时间(我)。他/她的时间戳。
I am currently thinking of creating multiple tables in my database for each webpage on my website, each of which would track an aspect of user activity on my site. E.g 1 table containing timestamp and userid of each user who visited that webpage, another table storing their actions done on the webpage(e.g liked something)
我目前正在考虑为我网站上的每个网页在我的数据库中创建多个表,每个表将跟踪我网站上用户活动的一个方面。E。g1表包含访问该网页的每个用户的时间戳和userid,另一个表存储他们在该网页上完成的操作(e)。克喜欢的东西)
Would this be a good way of tracking user activity or are there other, better methods of doing so?
这是一种跟踪用户活动的好方法吗?
PS: Im using PHP and MYSQL for the website, and am doing this as a means of improving my coding so i won't be using google analytics or anything like it.
PS:我在网站上用的是PHP和MYSQL,我这么做是为了改进我的代码,这样我就不用谷歌分析之类的东西了。
3 个解决方案
#1
5
Yep, store everything in a database. Have a table for user visits, one for user interactions etc.
是的,把所有东西都存储在数据库中。有一个用户访问表,一个用户交互表等等。
To start with have a table page_visits
that contains an ID for the user (This is your first problem to solve - how to uniquely identify a visitor. Identify them using their IP and or User agent? Create a cookie that refers to a unique ID? There are different methods depending on your goal - none are 100% fool-proof) and the page ID or URL they visited along with a timestamp.
首先要有一个包含用户ID的page_visit表(这是您要解决的第一个问题——如何惟一地标识访问者。使用他们的IP和用户代理来识别他们?创建引用唯一ID的cookie ?根据您的目标有不同的方法——没有一种是100%绝对安全的)以及他们访问的页面ID或URL以及时间戳。
Add a table to track interactions. How you capture the event is up to you, do you fire an AJAX call using Javascript or jQuery to log an event like a click? This table could contain fields such as user_id
, timestamp
, action_performed
, source_page_id
.
添加一个表来跟踪交互。如何捕获事件取决于您,您是使用Javascript还是jQuery来像单击一样记录事件的AJAX调用?这个表可以包含user_id、时间戳、action_performed、source_page_id等字段。
The way you decide to implement is entirely up to you but a database would probably be the way to go.
您决定实现的方式完全取决于您,但是数据库可能是实现的方式。
#2
1
try creating tables in your database to store the necessary information.
尝试在数据库中创建表来存储必要的信息。
Off the top of my head I could think to store their IP address
在我的头顶上,我可以考虑存储他们的IP地址。
get hold of some GEO information and you can use that IP address to obtain and store the country they are in.
获取一些地理信息,您可以使用该IP地址来获取和存储它们所在的国家。
You can store the webpage they were on before coming to your website.
你可以在进入你的网站之前储存他们的网页。
How many times they have came to your website and the pages they have visited and how many times on each page.
他们访问你的网站多少次,访问过多少页,每个页面上有多少次。
IP address can be obtained using
IP地址可以使用
$_SERVER['REMOTE_ADDR']
and
和
$_SERVER['HTTP_X_FORWARDED_FOR']
geo information to obtain their country can be obtained from many websites...Usually you have to pay for it if you want up to date info...some people off free older info which is still quite useful.
要获取他们国家的地理信息,可以从许多网站上获得……通常,如果你想要最新的信息,你需要付费。有些人放弃了免费的旧信息,这仍然是非常有用的。
Here is a good provider of GEO information that you pay for but it is very cheap
这是一个很好的地理信息提供商,你可以付费,但它非常便宜
http://dev.maxmind.com/geoip/geoip2/web-services/
http://dev.maxmind.com/geoip/geoip2/web-services/
to do the amount of visits just grab their IP address when they arrive, search your database for that IP and if it exists then increment the number of visits by 1. If not create a new visitor. Do the same incrementation on each individual page visit too.
要进行访问,只需在访问时获取他们的IP地址,在数据库中搜索该IP,如果存在,则增加访问次数1。如果不创建一个新的访问者。在每个单独的页面访问中也进行相同的递增。
use this to obtain the URL they were on before coming to your site
在访问你的站点之前,请使用它来获取它们的URL。
$_SERVER['HTTP_REFERER']
So a table like this:
像这样的表格
userId | userIP | userCountry | visits | webpage1Visits | webpage2Visits | webpage3Visits
Assuming you dont have thousands of pages this could work for a dozen or so pages.
假设你没有成千上万页的页面,这可以用十几页。
There a tonne of other stuff you can store like average time on site etc etc but this is the basic stuff.
还有很多其他的东西你可以在现场平均存储时间等等但这是基本的东西。
attempt it and when you come across problems along the way ask more questions and people will help :)
尝试一下,当你遇到问题的时候问更多的问题,人们会帮助你:
#3
0
you can use flag for each webpage and save the incremented flag value if he clicks on the webpage to the respective users login database to track which pages (s)he is clicking (this is only for the webpages who has the user database).
您可以为每个网页使用标志,并保存增加的标志值,如果他点击网页到相应的用户登录数据库,以跟踪他正在点击的页面(这仅针对拥有用户数据库的网页)。
#1
5
Yep, store everything in a database. Have a table for user visits, one for user interactions etc.
是的,把所有东西都存储在数据库中。有一个用户访问表,一个用户交互表等等。
To start with have a table page_visits
that contains an ID for the user (This is your first problem to solve - how to uniquely identify a visitor. Identify them using their IP and or User agent? Create a cookie that refers to a unique ID? There are different methods depending on your goal - none are 100% fool-proof) and the page ID or URL they visited along with a timestamp.
首先要有一个包含用户ID的page_visit表(这是您要解决的第一个问题——如何惟一地标识访问者。使用他们的IP和用户代理来识别他们?创建引用唯一ID的cookie ?根据您的目标有不同的方法——没有一种是100%绝对安全的)以及他们访问的页面ID或URL以及时间戳。
Add a table to track interactions. How you capture the event is up to you, do you fire an AJAX call using Javascript or jQuery to log an event like a click? This table could contain fields such as user_id
, timestamp
, action_performed
, source_page_id
.
添加一个表来跟踪交互。如何捕获事件取决于您,您是使用Javascript还是jQuery来像单击一样记录事件的AJAX调用?这个表可以包含user_id、时间戳、action_performed、source_page_id等字段。
The way you decide to implement is entirely up to you but a database would probably be the way to go.
您决定实现的方式完全取决于您,但是数据库可能是实现的方式。
#2
1
try creating tables in your database to store the necessary information.
尝试在数据库中创建表来存储必要的信息。
Off the top of my head I could think to store their IP address
在我的头顶上,我可以考虑存储他们的IP地址。
get hold of some GEO information and you can use that IP address to obtain and store the country they are in.
获取一些地理信息,您可以使用该IP地址来获取和存储它们所在的国家。
You can store the webpage they were on before coming to your website.
你可以在进入你的网站之前储存他们的网页。
How many times they have came to your website and the pages they have visited and how many times on each page.
他们访问你的网站多少次,访问过多少页,每个页面上有多少次。
IP address can be obtained using
IP地址可以使用
$_SERVER['REMOTE_ADDR']
and
和
$_SERVER['HTTP_X_FORWARDED_FOR']
geo information to obtain their country can be obtained from many websites...Usually you have to pay for it if you want up to date info...some people off free older info which is still quite useful.
要获取他们国家的地理信息,可以从许多网站上获得……通常,如果你想要最新的信息,你需要付费。有些人放弃了免费的旧信息,这仍然是非常有用的。
Here is a good provider of GEO information that you pay for but it is very cheap
这是一个很好的地理信息提供商,你可以付费,但它非常便宜
http://dev.maxmind.com/geoip/geoip2/web-services/
http://dev.maxmind.com/geoip/geoip2/web-services/
to do the amount of visits just grab their IP address when they arrive, search your database for that IP and if it exists then increment the number of visits by 1. If not create a new visitor. Do the same incrementation on each individual page visit too.
要进行访问,只需在访问时获取他们的IP地址,在数据库中搜索该IP,如果存在,则增加访问次数1。如果不创建一个新的访问者。在每个单独的页面访问中也进行相同的递增。
use this to obtain the URL they were on before coming to your site
在访问你的站点之前,请使用它来获取它们的URL。
$_SERVER['HTTP_REFERER']
So a table like this:
像这样的表格
userId | userIP | userCountry | visits | webpage1Visits | webpage2Visits | webpage3Visits
Assuming you dont have thousands of pages this could work for a dozen or so pages.
假设你没有成千上万页的页面,这可以用十几页。
There a tonne of other stuff you can store like average time on site etc etc but this is the basic stuff.
还有很多其他的东西你可以在现场平均存储时间等等但这是基本的东西。
attempt it and when you come across problems along the way ask more questions and people will help :)
尝试一下,当你遇到问题的时候问更多的问题,人们会帮助你:
#3
0
you can use flag for each webpage and save the incremented flag value if he clicks on the webpage to the respective users login database to track which pages (s)he is clicking (this is only for the webpages who has the user database).
您可以为每个网页使用标志,并保存增加的标志值,如果他点击网页到相应的用户登录数据库,以跟踪他正在点击的页面(这仅针对拥有用户数据库的网页)。