• Resolved gorky5

    (@gorky5)


    Hi. I’m using this plugin and it seems to do the job well, and I’m close to buying the paid add-on for CSV exporting.

    I’m having trouble with one thing, though: tracking the file downloads in Google Analytics. I know the plugin displays IP addresses but I’d like to see geographical spread, time, etc.

    To add Analytics tracking I’d normally amend the link to something like this:

    <a onclick="ga('send', 'event', 'Downloads', 'Click', 'PDF downloaded', '0');" href="https://example.com/filename.pdf">Download Link</a>

    There doesn’t seem to be an easy way to do this, because the plugin download link is dynamically generated, e.g.:

    https://example.com/?file=filename.pdf&nonce=5e90fca2bd03e4cec&email=address%40gmail.com

    Anyway, if I try to add tracking code in the Customize Messages page, the plugin strips everything out apart from the basic link. Is it possible to use custom hooks as a workaround, and if so, what would be needed?

    If you have any other idea how I might implement Analytics, or view more detailed data on where and when people are downloading the files, please let me know.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author mkscripts

    (@mkscripts)

    Hi,

    Yes, there is a filter available to adjust the email message including the download link (/wp-content/plugins/download-after-email/includes/shortcodes.php).

    $message = apply_filters( 'dae_email_message', $message, $values, $messages['email_content'], $file, $download_url );

    If you are using the placeholder {download_link} in your email message, you can replace this placeholder with your custom download link.

    If you have any more questions, feel free to ask.

    Kind regards,
    Team Download After Email

    soytandem

    (@soytandem)

    Hi!
    I’m looking for the same thing, add the Google tracking code, but I couldn’t understand the @mkscripts answer.
    Do I have to edit ‘shortcodes.php’ file and then change what?
    Sorry, I’m not an expert and I’m stuck with this since I have 6 downloads to track.
    Could you help me?
    Thanks in advance!

    Plugin Author mkscripts

    (@mkscripts)

    Hi,

    Below an example of the use of the above-mentioned filter:

    add_filter( 'dae_email_message', 'my_custom_dae_download_link', 10, 5 );
    function my_custom_dae_download_link( $message, $values, $email_content, $file, $download_url ) {
    
        // Your custom download link
    
        $download_link = '<a href="' . $download_url . '">' . $file . '</a>';
    
        // Replace the placeholder {download_link} with the $download_link
    
        $message = str_replace( '{download_link}', $download_link, $message );
    
        return $message;
    
    }

    (This is an example, please test it before using it on a live site.)

    Changing the source code is not recommended, because after a plugin update these changes can be lost. That is why actions and filters are used to make changes or to add custom code. Here you can find more information about adding filters:

    https://developer.www.ads-software.com/reference/functions/add_filter/

    You can add this code to the functions.php of your child theme or via a custom plugin.

    Kind regards,
    Team Download After Email

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Analytics and tracking’ is closed to new replies.