• Resolved Winework

    (@winework)


    Hi Everyone,

    Can anyone offer me some advice?

    I have an Image Library on my website where clients and their marketing partners can download product image files.

    However, downloads do not appear in Yoast/Google Analytics and so I can’t measure how widely the service is used.

    The URL is: http://www.winework.com/our-services/winework-solutions-images/product-image-library/

    The code used to generate the page returned from the brand selection is…

    <p><span style="font-size: 12pt;">To download an image file, simply click on the image.</span></p>
    <form id="mla-text-form" class="row" action="." method="post">
    <p><span style="color: #000000; font-size: 12pt;"><strong>Select a Brand to View...</strong></span></p>
    <p>[mla_term_list taxonomy=attachment_category child_of=26 mla_output=dropdown mla_option_value="{+slug+}" show_count=true pad_counts=false ]</p>
    <p><input id="text-form-submit" name="text_form_submit" type="submit" value="GO" /></p>
    </form>
    <h3><span style="color: #cb0131;">Search Results</span></h3>
    <p>[mla_gallery]<br />
    attachment_category="{+template:({+request:tax_input.attachment_category+}|kumeu-river)+}" posts_per_page=20 mla_output="paginate_links, prev_next"<br />
    mla_link_href='{+new_url+}?tax_input[attachment_category]="{+query:attachment_category,text+}"'<br />
    [/mla_gallery]</p>
    <p>[mla_gallery]<br />
    attachment_category="{+template:({+request:tax_input.attachment_category+}|kumeu-river)+}" size="thumbnail" posts_per_page=20 orderby="title"<br />
    [/mla_gallery]</p>
    <p>[mla_gallery]<br />
    attachment_category="{+template:({+request:tax_input.attachment_category+}|kumeu-river)+}" posts_per_page=20 mla_output="paginate_links, prev_next"<br />
    mla_link_href='{+new_url+}?tax_input[attachment_category]="{+query:attachment_category,text+}"'<br />
    [/mla_gallery]</p>

    Any suggestions or guidance on how to measure file downloads by specific file will be most welcome.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author David Lingren

    (@dglingren)

    Thanks for your question and for your patience in awaiting my response while I was traveling and without Internet access. Thanks as well for posting the code used to generate the page; very helpful.

    I am a bit puzzled by your code. The gallery generation shortcode is:

    <p>[mla_gallery]<br />
    attachment_category="{+template:({+request:tax_input.attachment_category+}|kumeu-river)+}" size="thumbnail" posts_per_page=20 orderby="title"<br />
    [/mla_gallery]</p>
    

    I don’t see how this generates the mla-file-downloader.php links in your example page. Are you using a custom markup template or some other means to generate these links?

    That said, your question is similar to that posed in this earlier topic:

    Force Download breaks Google event tracking

    I believe the answer to your question will be to add an onclick= attribute to the links in the gallery. To do that I will need the answer to the questions I posed in the earlier topic:

    1. I assume you want to track this as an event, not a “virtual page” hit; is that right?
    2. If that’s right, can you tell me the values you want to describe the event, i.e., Category, Action, Label, Value?
    3. Are you using Universal Analytics (analytics.js) or Classic Analytics(ga.js)? It looks like your example page is using analytics.js.

    Let me know your answers, especially item 2. above, and I will investigate further.

    Thread Starter Winework

    (@winework)

    Hi David,

    Really appreciate you coming back to me and your offer of help.

    Yes, I am using a custom markup template. I can send you the details if you wish.

    To answer your questions…

    1) Yes, I think tracking as an event is the better option.

    2) Don’t really know what my options are… but how about these?

    Category: Image Library
    Action: Download
    Label: [File Name]
    Value: [att category id]

    3) I’m using Universal Analytics.

    Thanks in advance.

    Colin

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update with the additional information. I have developed and tested a solution that might work for you.

    First, The source code for the example page you referenced indicates that you are using:

    Google Analytics by MonsterInsights plugin v7.4.2

    My test site uses a different WordPress plugin:

    Google Analyticator

    The plugin I am using sends Google Analytics Events by attaching a bit of JavaScript code to each hyperlink it finds. On my test site this worked with the gallery items generated by my [mla_gallery] shortcode. You might find that your plugin offers something similar; perhaps the MonsterInsights support team can help with that.

    You can also try the alternative solution I came up with. Since the Google Analytics code is already loaded on your example page, all you have to do is add an onclick handler to the links in your [mla_gallery] output. You are already using a custom template, so a modification along the lines I worked out should be straightforward.

    You wrote “Don’t really know what my options are…” You can find more information about the values associated with each event at:

    Event Tracking

    For my test template (below) I used:

    • Category: ‘download’
    • Action: ‘PDF’
    • Label: ‘[+file+]’ (name of the file downloaded)
    • Value: (not used)

    You can see the first three values in the template source text. For your application, change them as you see fit. Note that the “Value” is defined as an integer in the Google documentation. Your [att category id] would work, but you will have to find a way to derive it from the slug value passed in to the shortcode. You could use the slug itself (e.g., [+query:attachment_category,single+]) as the Category or Action value, if that makes sense in your application.

    Here is the “Item” section of the custom markup template I used for my testing:

    <[+itemtag+] class='gallery-item [+last_in_row+]'>
    	<[+icontag+] class='gallery-icon [+orientation+]'>
    		<a onclick="ga('send', 'event', 'download', 'PDF', '[+file+]');" href="[+filelink_url+]" target="_blank">[+thumbnail_content+]</a>
    	</[+icontag+]>
    	[+captiontag_content+]
    </[+itemtag+]>
    

    In the third line of the template I have replaced the default [+link+] value with a hyperlink that includes the onclick="ga('send', 'event', 'download', 'PDF', '[+file+]');" attribute. You should be able to add that to your own template; if you need more specific guidance, post your template here and let me know.

    I hope that gets you started on a solution. I am marking this topic resolved, but please update it if you have any problems or further questions regarding the above suggestions. Thanks for an interesting question!

    Thread Starter Winework

    (@winework)

    Hi David,

    Firstly, apologies for being so slow to respond to your help. I too have been away recently.

    I think I understand your instructions, here’s what I have done…

    1) Changed my analytics plugin from MonsterInsights to Google Analyticator.

    2) Edited the “Item” section of my custom product_mu template to add the onclick handler, as follows….

    <td class='gallery-icon'>
        [+downloadlink+]
      </td>
      <td class='wp-caption-text gallery-caption'>
    <font color="black"><strong>[+title+]</strong></font><br />
    <br>     
    <strong>File Name:</strong> [+file+]<br />
    <strong>File Type:</strong> [+terms:category+]<br />
    <strong>File Format:</strong> [+mime_type+]<br />
    <strong>Dimensions:</strong> [+dimensions+] px<br />
    <strong>File Size:</strong> [+file_size,commas+] bytes<br />
    <onclick="ga('send', 'event', 'download', '[+query:attachment_category,single+]', '[+file+]');">
    </td>

    I’m not sure if I have the syntax of the onclick handler correct. Can you comment?

    My thanks in advance.

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your update and especially for the text of your template section; very helpful.

    IF you go back to my proposed solution you will see that the onclick argument must be part of the hyperlink itself, not the table cell with the “thumbnail” display. For your template, remove the <onclick=… you have now and replace [+downloadlink+] (the hyperlink) with this alternative:

    <a onclick="ga('send', 'event', 'download', [+query:attachment_category,single+]', '[+file+]');" href="[+downloadlink_url+]" target="_blank">
    `

    I am traveling again and away from my development system, but I believe this will give you the results you want. Let me know if you have problems or further questions regarding the above suggestion.

    Thread Starter Winework

    (@winework)

    Hi David,

    Thank you once again.

    I have tried the code as you suggested, but replacing [+downloadlink+] results in the thumbnail (which is also the download “button”) failing to display, which means the file cannot be downloaded by the user.

    Do you have a suggested edit?

    I think we’re really close to success!

    Colin

    Plugin Author David Lingren

    (@dglingren)

    Thanks for giving my suggestion a try. I’m on the road so I couldn’t test it myself and I only gave you part of the solution.

    Give this more complete solution a try:

    <a onclick="ga('send', 'event', 'download', [+query:attachment_category,single+]', '[+file+]');" href="[+downloadlink_url+]" target="_blank">[+thumbnail_content+]</a>
    

    The added portion, [+thumbnail_content+]</a>, should restore the thumbnail and give you something to click on.

    Thread Starter Winework

    (@winework)

    David,

    That works perfectly!

    Best plugin support on WordPress!

    Many thanks,

    Colin

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Image Library Download Analytics’ is closed to new replies.