This topic is locked
[SOLVED]

 Click Tracking Analytics

5/1/2015 2:32:01 PM
PHPRunner General questions
S
salus1 authorDevClub member

Has anyone got a method that could be used to track queries and clicks in a public PHPRunner-based web catalog?

Sergey Kornilov admin 5/4/2015

Google Analytics?

S
salus1 authorDevClub member 5/4/2015

Thanks for your reply. Google Analytics Flow Visualization is close but I'm wondering if there isn't a much simpler way to this without the overhead. Is there a way to utilize PHPRunner's capability to save searches, automatically writing each query to a log?

Sergey Kornilov admin 5/4/2015

You can definitely do that using events like BeforeSQLQuery:

http://xlinesoft.com/phprunner/docs/before_sql_query.htm
Should be fairly straightforward if you only need to log search queries but you will have to add it some code to each table's BeforeSQLQuery event.

S
salus1 authorDevClub member 5/4/2015

Thanks for this info. It seems like this is more for altering a query on the fly as opposed to capturing the query parameters. Any chance of example event code for capturing the query parameters and writing them to a database?

Sergey Kornilov admin 5/4/2015

$strSQL variable contains the whole SQL query. This is all what you need.

S
salus1 authorDevClub member 5/4/2015

OK, thanks. I added the event as suggested...
$sql = "INSERT INTO searches (queryinfo) values ('$strSQL')";

CustomQuery($sql);
...and while the initial page load works and writes to the log table any added parameter causes a syntax error...
INSERT INTO searches (queryinfo) values ('SELECT Serial, Shape, Weight, Color, Clarity, Cut, Lab, Price, video, report, analysis, appraisal FROM inventory where (Shape='Emerald') ')
...due to the single quotes around the parameter.
Is there a way to change or comment out the quotes?

S
salus1 authorDevClub member 5/4/2015

Put my thinking cap on and did a PHP str_replace...
$newsql = str_replace("'"," ",$strSQL);

$sql = "INSERT INTO searches (queryinfo) values ('$newsql')";

CustomQuery($sql);
...and now all is working well.
Thanks as always for pointing me in the right direction.