Hi there,
I'm having trouble with some downloads being tracked. I think it's to do with the fact that my download links are generated from post meta data. So I do something like:
$url = get_post_meta( get_the_ID(), '_some_meta_var', true );
printf('<a href="%s>%s</a>, $url, "My download");
I'd assumed that GA4WP would use JavaScript to scan the page for links and inject the relevant "onClick" code, or just use a function that triggers on any anchor tag but it seems that it doesn't work this way.
From looking at the GA4WP code it seems that you filter links in the_content (and various other places) and inject the tracking code there, for each link. This won't, obviously, apply to my custom download links.
Is there, therefore, a recommended way of tracking my links. Perhaps by applying one of the GA4WP filters to my links before printing them. Something like:
$url = get_post_meta( get_the_ID(), '_some_meta_var', true );
$link = printf('<a href="%s>%s</a>, $url, "My download");
if (class_exists('GA_Filter')) {
$link = GA_Filter::the_content($link);
}
Is this the kind of thing I should be doing? Or is there a better way?
Thanks
http://wordpress.org/extend/plugins/google-analytics-for-wordpress/