Creating Your Own Website Analytics

I decided that Google Analytics is not the best way to get around the exact numbers, since users who do not have JavaScript enabled in the browser will not be counted. Therefore, I would like to start creating my own Anylytics.

I have a table that will record the user's IP address, page URL and date / time.

Then I have a script that is at the bottom of each page of the site, which then runs an SQL query to send data to the database.

Here is the script.

$page_viewed = mysql_real_escape_string($_SERVER['REQUEST_URI']); if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } $ip = mysql_real_escape_string($ip); mysql_query("And then do the sql query.... "); 

Since most of you here are experience developers, I want to know if you have any improvements in my scenarios or something that needs to be changed.

+4
source share
4 answers

This seems like a bad idea ... Typically, what happens for analytics when a user does not support javascript, their browser parses what is contained in the html tags. As a rule, in them you can contain one pixel image or something similar (the purpose of the image is to call the code, as you indicated above). Use this query to get information about clients who do not have javascript capabilities, and not to embed all in one boat.

+2
source

If you use Apache, all this is written to your log files. You can use something like http://awstats.sourceforge.net/ to analyze them.

Logging in with MySQL and PHP is about to kill your server if you have any non-JS-enabled traffic that is worth analyzing.

+1
source

As @Blowski mentioned above, there are better options. I have used Mint in the past and this is an incredible service. It is written in PHP, and is beautiful to learn and easy to understand.

I recommend that you spend some time looking at the main functions , as well as screencasts and screenshots , before spending more time looking for the wheel inventor - your time is valuable.

0
source

Because browser cache and javascript, you will find that parsing log files is not 100% accurate. Combining log analysis and page tags is the best choice for most websites. I used Nihuo and google analytics as in past years, they work great for me.

0
source

Source: https://habr.com/ru/post/1413395/


All Articles