Created
October 3, 2012 14:43
-
-
Save hidesakai/3827296 to your computer and use it in GitHub Desktop.
フォーム内容をGAトラックイベントへPush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gaForm = gaForm || {}; | |
jQuery(function($) { | |
var defaults = { | |
Forms:"#form", | |
Category:"analysisForm", | |
Action:"id", | |
inputRadio: true, | |
inputSelect: true, | |
inputCheckBox: true | |
}; | |
var options = $.extend(defaults, gaForm); | |
$(options.Forms+' input:submit').click(function() { | |
var radio = $(options.Forms+' input:radio:checked'); | |
var formtext = $(options.Forms+' input:text'); | |
jQuery.each(formtext, function(i,val) { | |
_gaq.push(['_trackEvent', options.Category, $(this).attr(options.Action), $(this).val()]); | |
}); | |
jQuery.each(radio, function(i,val) { | |
_gaq.push(['_trackEvent', options.Category, $(this).attr(options.Action), $(this).val()]); | |
}); | |
var select = $(options.Forms+' select'); | |
jQuery.each(select, function(i,val) { | |
_gaq.push(['_trackEvent', options.Category, $(this).attr(options.Action), $(this).val()]); | |
}); | |
var checkbox = $(options.Forms+' input:checkbox:checked'); | |
jQuery.each(checkbox, function(i,val) { | |
_gaq.push(['_trackEvent', options.Category, $(this).attr(options.Action), $(this).val()]); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment