Posted By

freezy on 04/27/11


Tagged

form link google click submit multiple Analytics GA tracker


Versions (?)

Google Analytics tracking link click and form submit to multiple trackers


 / Published in: JavaScript
 

usage: <a href="" onclick="recordOutboundLink(link, category, action, opt_label, opt_value);return false;"> <form id="uniqueID" onsubmit="trackFormSubmit(form, category, action, opt_label, opt_value);return false;">

  1. var arrTracker = ['trackerName1', 'trackerName2']; // tracker names
  2. // tracking form submit
  3. function trackFormSubmit(form, category, action, opt_label, opt_value) {
  4. for (var i = 0, ii = arrTracker.length; i < ii; i++) {
  5. _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
  6. }
  7. setTimeout("document.getElementById('"+form.id+"').submit();", 100);
  8. return false;
  9. }
  10.  
  11. // tracking link click
  12. function recordOutboundLink(link, category, action, opt_label, opt_value) {
  13. for (var i = 0, ii = arrTracker.length; i < ii; i++) {
  14. _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
  15. }
  16. setTimeout('document.location = "' + link.href + '"', 100);
  17. return false;
  18. }
  19.  
  20. <a href="" onclick="recordOutboundLink(link, category, action, opt_label, opt_value);return false;">
  21. <form id="uniqueID" onsubmit="trackFormSubmit(form, category, action, opt_label, opt_value);return false;">

Report this snippet  

You need to login to post a comment.