The download event tracking provided by the Google Analytics module is incompatible with the file rewriting that file entity employs.

File entity rewrites everything to /file/ID/download so when the javascript click event fires on the link the javascript scans to see whether one of the tracked file types is being clicked on. Because the url does not have an extension that matches (it has no extension at all) it doesn't trigger a download event in Analytics.

To resolve this I reverted back to standard url handing as per core's defaults (sites/default/files/etc) which correctly allows the click event to trigger on the detected file path. I did this by overriding the theme function theme_file_entity_download_link(), removing the line:
$uri = file_entity_download_uri($file);and adding:

$uri = array(
    'path' => file_create_url($file->uri),
    'options' => array()
  );

I'd be interested to know what people think to this? I've marked this as a bug report, although it's not really a bug as it works as designed. It's just the design that excludes compatibility with analytics (unless I've missed something).

Comments

dave reid’s picture

Category: Bug report » Support request

Definitely not a bug

tanc’s picture

Maybe this should be a feature request? Make File Entity compatible with Google Analytics module download click tracking. In the issue I opened in the GA module queue, the developer hass left a fairly terse reply and closed the ticket: "I don't know what you expect from a statistic that has the same url all times. Makes no sense to me."
Hoping to get a bit more interest or thought expressed in this queue.

tanc’s picture

sheldonkreger’s picture

Keep in mind, data tracked this way will only be valid if you use the fid/download scheme on every instance of a download on your site. Frequently, content editors will manually place hard links to files directly into content with href = sites/default/files/filename.ext . . . such links will obfuscate your Google data into oblivion, even if this feature were implemented.

kbrinner’s picture

I ran into this problem and wrote an in-depth blog post about how to track file downloads when using Google Analytics and the File Entity module. Hope it helps someone who finds themselves here looking for a solution.