I need to count how many times a user clicked a specific button, for example:
<a id="download" href="#">Download</a>
What´s best practice here? I think about to create a completely new database table and increment the value each time a user clicks on the button.
function countClicks() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
//* Create the teams table
$table_name = $wpdb->prefix . 'count_clicks';
$sql = "CREATE TABLE $table_name (
click_id INTEGER NOT NULL AUTO_INCREMENT,
click_number INTEGER NOT NULL,
PRIMARY KEY (click_id)
) $charset_collate;";
dbDelta( $sql );
}
Do you have better solutions for this instead of creating a fresh new table? Btw: It´s a WordPress website.