I recently started a Tumblr blog to help gamers find the best prices on their favorite video games, and like any self respecting content publisher I immediately set about adding analytics to the site so that I could track how well my content was converting. I ran into a few snags along the way when adding outbound link tracking with Google Analytics, so hopefully this guide will help save the next blogger some time.

  1. Click the customize link at the top of your blog.

  2. Click the ‘Edit HTML’ button.

    Tumblr's Edit HTML Button

    It should look something like this:

    Tumblr's HTML Editor

  3. Add the below code into your blog’s HTML:

        <!-- Rest of the <head> content here -->
        <!-- Include jQuery -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <!-- Rest of the <body> content here -->
            // Load Google Analytics
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            // Send a pageview event for your domain / GA account
            ga('create', 'UA-XXXXXXXX-X', 'example.com');
            ga('send', 'pageview');
            // Listen for clicks from outbound links
            jQuery("a[href*='http://']:not([href*='" + window.location.hostname + "'])").click(function(e) {
                // Send a click event with the href as the label
                    ga('send', 'event', 'Outbound Link', 'click', jQuery(this).attr('href'));
                catch (err)
                // Delay the page's loading for 100 milliseconds to allow Google time to send the click event
                setTimeout('document.location = "' + jQuery(this).attr('href') + '"', 100);
                // Prevent the page from loading

Don’t forget to swap in your domain and GA account id in the script block before the end of the body.

It’s also worth noting that the above code should work fine for adding outbound link tracking to Google Analytics on any website. Hope this was helpful, and happy Tumbling!