A hit counter is the best way to track your compaign and calculate each compaign Click-through rate (CTR).
A compaign or a product with higher CTR is the one that will bring more sales and more leads.
Table of Contents
How the hit counter works ?
Lets suppose you will show a Newsletter pop-up to your customers , and you wanna track its conversion to subscription.
Link your pop-up message to a specific url that will trigger an additional click then redirect to the Newsletter subscription.
The conversion rate is the number of subscription devided by the total count of hits on the Newsletter pop-up link.
Link the pop-up or the menu of newsletter subscription to Yourdomain/hit.php?u=1
in our website it is linked to :
Each click on the Newsletter menu will be counted in the file
However, the HTML that will show you the statistics for this link is :
The result of the first link will be like this :
You can add a hit counter using a simple PHP code, the code will be split to multiple phase , and here they are :
Create the “hit.php” file
Open notepad or go to your Cpanel account that your host provided for you.
Insert the PHP code that we will provid to you above , and save it .
In case you are working on a live file save it then upload it using the upload area on the Cpanel account.
Catch the hit URL
this code will catch the data transfered using a php file with a variable in the url like ?u=
example of a tracking link
Make your own url link list to track
Using this method you will affect a specific code for each url to track that will trigger a counter using a simple and smooth url , like :
The above url will trigger the counter and redirect the first url link by clicking it.
Create a Counter file for each URL
This code will generate a txt file for each tracked url.
If a link line is number 1 the tracking file that will be holding the number of clicks will be
Implement the counter of hits
This code will read the content of the hit file’s counter and implement 1 additional visit and re-create a new file contain the new count of hits.
This will happen for each file before any redirection action.
Add a redirection function
This function will redirect to any set variable in the $url parameter.
Here is the full hit.php file :