I have a plugin that manages links in Wordpress, with images and texts pretending to be related articles, all are external links. (Taboola Type).
I would like to add some parameters at the end of the Links. Ex:
Link == > otherite.com
I want to add the following now:
Link == > otherite.com?src=urldinamicadowordpress
So I can see the source of these clicks and which article is converting more clicks.
If possible, still add if the click came from mobile or Desktop
Link == > otherite.com?src=urldinamicadowordpress|mobile
Link == > otherite.com.br?src=urldinamicadowordpress|desktop
Redirect Code
add_action('init', 'count_clicks');
function count_clicks()
{
global $wpdb;
if(isset($_GET['action']) && $_GET['action'] == 'count') {
$id = $_GET['id'];
$tableName = $wpdb->prefix . 'post_related_meta';
$meta = $wpdb->get_results($wpdb->prepare("select meta_clicks, meta_link from $tableName where meta_id = %s", $id));
$meta = $meta[0];
$wpdb->update($wpdb->prefix."post_related_meta", array(
'meta_clicks' => (int)$meta->meta_clicks+1,
), array(
'meta_id' => $_GET['id']
),
array(
'%d'
)
);
$redirect = $meta->meta_link;
header("Location: $redirect");
exit;
}
}