• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Download Monitor & Manager Plugin

Simple Download Monitor & Manager for WordPress

  • Home
  • Documentation
  • Addons/Extensions
  • Login
    • Sign In
    • Edit Profile
    • My Downloads
  • Support
    • Tutorials
    • Forum
    • Forum Search
    • Forum Login
    • Forum Registration
  • Contact Us
You are here: Home / Topics / Download Hook for Analytics

[Resolved] Download Hook for Analytics

· ·

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 5 years, 11 months ago by smythsys.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • June 20, 2019 at 2:03 pm #1219
    smythsys
    Participant

    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.

    June 20, 2019 at 3:12 pm #1220
    admin
    Keymaster

    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.

    June 20, 2019 at 8:35 pm #1221
    smythsys
    Participant

    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.

    July 1, 2019 at 12:17 pm #1251
    smythsys
    Participant

    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 } );
    
  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

Primary Sidebar

Featured Addons

  • Squeeze Form Addon
  • Hidden Downloads Addon
  • Amazon S3 Integration

Support Links

  • Support Forum

Search

Featured Plugin

WP Express Checkout Plugin

Start managing and tracking your file downloads with the simple download monitor plugin. Download Now

Copyright © 2025 | Simple Download Monitor | A member of the Tips and Tricks HQ family.