- This topic has 3 replies, 2 voices, and was last updated 5 years, 4 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Download Monitor & Manager Plugin
Simple Download Monitor & Manager for WordPress
· ·
WordPress Download Monitor Plugin › Forums › Download Monitor Plugin Forum › Download Hook for Analytics
Tagged: hook
Hi,
I’m trying to listen to the download event through Google Analytics, but I can’t find the correct hook when someone clicks on a download.
This is our code:
add_action( ‘wp_footer’, function () { ?>
<script>
document.addEventListener( ‘sdm_process_download_request’, function( event ) {
gtag(‘event’, ‘descarga’, { ‘event_category’: ‘descarga’, ‘event_action’: ‘enviar’,
‘event_label’: ‘es’, ‘value’: ‘0’});
}, false );
</script>
<?php } );
Could you help us ???? The Google Analytics code is correct because we use it with other plugins. But we just can’t find the correct event to listen to.
That code doesn’t look right to me in the context of our plugin.
The following action hook is triggered only when an item is being downloaded. There is no “wp_footer” code that will run for that action (when the download is being served, it doesn’t load the full wp page).
sdm_process_download_request
If you want to add some JavaScript to the footer of your site, probably better to listen for the click on a download button using your own JavaScript code.
The add_action( ‘wp_footer’, function () {—–}) adds that code to the footer.
And it is being added correctly. We see the script on the footer of the page.
stackoverflow.com/questions/48707083/wp-footer-not-load-plugin-script-in-wordpress
We are using this code for CF7 and it triggers the sent events.
But we can’t find an event for the download action.
Is there one we can use?
But I hadn’t thought on the onclick button JS. I could use the sdm_fancy2_download_dl_link class.
Thanks, I will try that. And add the code if it works for anyone who needs it.
In case someone needs it, this worked (change event as appropiate):
add_action( 'wp_footer', function () { ?>
<script>
document.addEventListener('click', function(e) {
if (e.target.className == 'sdm_fancy2_download_dl_link')
{
gtag('event', 'descarga', { 'event_category': 'descarga', 'event_action': 'enviar',
'event_label': 'es', 'value': '0'});
}
});
</script>
<?php } );
Start managing and tracking your file downloads with the simple download monitor plugin. Download Now