Support » Plugin: Google Doc Embedder » How to include Google Analytics tracking code in embedded document's URL

  • Hi!

    Congrats for this great plugin.

    I would want to know how can I include Google Analytics tracking code in embedded document’s URL (if possible).

    I’m referring to _trackEvent(category, action, opt_label, opt_value) that you must include in a downloadable file so as GA can track the number of timer it has been downloaded by the visitors.

    Thanks in advance!

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



    I’m not sure if _trackevent can be applied to iframes. You can certainly add that tracking code to the download link with a little edit of the plugin source. If you already know what the proper code is to apply to the download link, you can find it on line 160 of the file gviewer.php (in version 2.0 of the plugin):

    $linkcode .= "<p class=\"gde-text\"><a href=\"$dlFile\" target=\"$target\" class=\"gde-link\">$txt</a></p>";

    Add the (properly escaped) onclick event to this line. I am not personally a heavy user of Google Analytics so I can’t say exactly what that code should be. I will consider adding this as an automated option to a future version if it’s useful.

    If I’m missing your point here, please do clarify. Thanks for your kind comments about the plugin.


    I completely agree!

    Awesome plugin – but would make it so much more awesome, if you included the Google Analytics event tracking for the download link.

    I am about to reveal my master’s thesis on my website and would like to use this plugin for it. However, I would really like to see stats on which companies that downloaded my thesis and Google Analytics is the way to do it.

    If we use your suggestion Kevin doesn’t that mean that the change we implement in the gviewer.php will be overwritten the next time we update the plugin?

    I would be so grateful if you could implement the event tracking in a way that allows us to fill in the following in the admin interface:

    • category (required)

      The name you supply for the group of objects you want to track.

    • action (required)

      A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.

    • label (optional)

      An optional string to provide additional dimensions to the event data.

    • value (optional)

      An integer that you can use to provide numerical data about the user event.

    Plugin Author k3davis



    You are correct that if you use my initial suggestion, it would not persist across versions. As such it was not good advice – just an attempt to provide an immediate solution to a problem nobody had ever raised before.

    In the wake of that realization, the plugin has supported Google Analytics tracking since version 2.1, albeit in a more limited mode than you’re suggesting. When enabled (it’s exposed on the settings page in the download link options), it sends to GA a category of “Download” and an action of the URL of the downloaded file.

    I use GA on an extremely limited basis and as such I’m relying on examples I could find online to implement this. I welcome your feedback as to whether or not it functions as intended and what the rationale might be behind extending the data further to include specific customization per URL or values for the optional elements. I would consider adding them (fixing-if broke/improving/extending this function) if I had a good tester and a better understanding of the purpose of each string and how it would normally be used by very GA literate people such as yourself.

    Hope this helps.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to include Google Analytics tracking code in embedded document's URL’ is closed to new replies.