Chapter 5
[ 97 ]
How is All the Data Tracked?
The logUserTrail() function gets called on every request to our site. In the function,
we can get the current page and last page links using the HTTP_REQUEST_URI and
HTTP_REFERER server-side variables. We are storing the session and user IDs so that
we can run queries on them later. The serialize() function takes all the variables
in the current request and converts them into a string. This will allow us to track the
actual step in the order process or the address the user was entering.
We can now query the collected data and get insights into how customers are using
our application. Some interesting queries could be:
Find all exit pages: SELECT * FROM trackingData WHERE timeSpent = 0
Find pages slow to process for the user: SELECT * FROM trackingData WHERE
timeSpent > 20.
Find popular modules: SELECT action, count(*) as total FROM
trackingData GROUP BY action ORDER BY total DESC.
Covering Problem Areas
We are just tracking successful requests in the current process. If we add an HTTP
error handler page, we can also track causes of HTTP errors like 404, 500 or others.
We can also add an exception/error handler in PHP, which can track the source of
problems in PHP code as well.
Pages:
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138