|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Tracking Outbound Forms and Links with Google Analytics |
| 4 | +--- |
| 5 | + |
| 6 | +In this tutorial, we will be taking a look at how we can track outbound links |
| 7 | +with Google Analytics. |
| 8 | + |
| 9 | +The default Google Analytics tracking snippet only tracks when a page is first |
| 10 | +loaded by sending a page view event which is good data to have but there are |
| 11 | +times when we need more information about certain events, for example the |
| 12 | +number of times outbound affiliate links are clicked. |
| 13 | + |
| 14 | +## Automatic Tracking |
| 15 | + |
| 16 | +Google Analytics actually supports plugins which can be used to extend its |
| 17 | +capabilities. These plugins can be written by anyone but Google does provide |
| 18 | +a few themselves and and one of these is called "autotrack" which does |
| 19 | +everything we need. |
| 20 | + |
| 21 | +The autotrack plugin is actually a collection of plugins which deal with automatic and |
| 22 | +declarative event tracking, two of these are "outboundFormTracker" and |
| 23 | +"outboundLinkTracker" which deal with automatic form and link tracking |
| 24 | +respectivly. |
| 25 | + |
| 26 | +To enable the "autotrack" plugin we just need to push a `require` onto the |
| 27 | +tracker stack with the plugin name. |
| 28 | + |
| 29 | +```html |
| 30 | +<script type="text/javascript"> |
| 31 | + window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; |
| 32 | +
|
| 33 | + ga('create', 'UA-XXXXX-Y', 'auto'); |
| 34 | + ga('require', 'autotrack'); |
| 35 | + ga('send', 'pageview'); |
| 36 | +</script> |
| 37 | + |
| 38 | +<script async src='https://www.google-analytics.com/analytics.js'></script> |
| 39 | +<script async src='path/to/autotrack.js'></script> |
| 40 | +``` |
| 41 | + |
| 42 | +## Conclusion |
| 43 | + |
| 44 | +The "autotrack" plugin provides a really easy and clean way to enable many |
| 45 | +common cases of event tracking, it has more functionality than what is covered |
| 46 | +here so make sure to [check out the |
| 47 | +documentation](https://github.com/googleanalytics/autotrack) for more advanced |
| 48 | +usage. |
0 commit comments