WordPress Download Monitor Plugin › Forums › Download Monitor Plugin Forum › Download Hook for Analytics
Tagged: hook
- This topic has 3 replies, 2 voices, and was last updated 6 years, 4 months ago by smythsys. 
- 
		AuthorPosts
- 
		
			
				
June 20, 2019 at 2:03 pm #1219smythsys ParticipantHi, 
 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. June 20, 2019 at 3:12 pm #1220admin KeymasterThat 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. June 20, 2019 at 8:35 pm #1221smythsys ParticipantThe 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.July 1, 2019 at 12:17 pm #1251smythsys ParticipantIn 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 } );
- 
		AuthorPosts
- You must be logged in to reply to this topic.