WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Tracks downloads with WordPress username as metadata? (3 posts)

  1. sharris203
    Member
    Posted 3 years ago #

    I would love if it were possible to track the current logged in username as metadata on downloads/clicks. Can I set this up as a custom variable?

    I'm thinking something like this may be possible:
    http://site.com/file.zip?username
    where [username] dynamically changes based on who is logged in.

    User meta plugin could assist in this:
    http://wordpress.org/extend/plugins/user-meta-shortcodes/

    Any ideas?

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

  2. sharris203
    Member
    Posted 3 years ago #

    Solved.

    Using "Shortcode Exec PHP" plugin
    http://wordpress.org/extend/plugins/shortcode-exec-php/

    I made a shortcode [user_login] that returns:

    global $current_user;
    get_currentuserinfo();
    return $current_user->user_login;

    Looking at the standard Google Analytics link tracking code:
    http://www.google.com/support/analytics/bin/answer.py?answer=55527

    I put the shortcode [user_login] in the link:
    <a href="/file.zip" onClick="recordOutboundLink(this, '[user_login]', 'file.zip');return false;">Download</a>

    Works! Maybe this can be simplified further using settings within the plugin to add [user_login] to every link on the entire site...

  3. sharris203
    Member
    Posted 3 years ago #

    One step closer... the shortcode above isn't handled properly when used within this plugin. This is how links turn out, more or less:

    <a onclick="javascript:_gaq.push(['_trackPageview','[user_login]/download/mysite.com/file.zip']);" href="http://mysite.com/file.zip">Download</a>
    Is there a way to edit the plugin to escapes the [user_login] shortcode?

    I think it could also work easily like this:
    <a id="[user_login]" href="/file.zip">Download</a>
    if G.A. tracks the id="" part.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic