Skip to content

Instantly share code, notes, and snippets.

@Shoora
Forked from hidesakai/jquery.gaformanalysis.js
Last active April 21, 2019 18:35
Show Gist options
  • Save Shoora/0a3cb400b4bf36e81597 to your computer and use it in GitHub Desktop.
Save Shoora/0a3cb400b4bf36e81597 to your computer and use it in GitHub Desktop.
jquery.gaformanalysis
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()]);
});
});
});
var gaForm = gaForm || {};
jQuery(function($) {
var defaults = {
Forms:".wpcf7-form",
Category:"DATAFORM",
Action:"class",
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');
var textareatext = $(options.Forms+' textarea');
jQuery.each(formtext, function(i,val) {
/* console.log("send","event",options.Category,$(this).attr(options.Action),$(this).val()) */
ga("send","event",options.Category,$(this).attr(options.Action),$(this).val())
});
jQuery.each(textareatext, function(i,val) {
/* console.log("send","event",options.Category,$(this).attr(options.Action),$(this).val()) */
ga("send","event",options.Category,$(this).attr(options.Action),$(this).val())
});
jQuery.each(radio, function(i,val) {
/* console.log("send","event",options.Category,$(this).attr(options.Action),$(this).val()) */
ga("send","event",options.Category,$(this).attr(options.Action),$(this).val())
});
var select = $(options.Forms+' select');
jQuery.each(select, function(i,val) {
/* console.log("send","event",options.Category,$(this).attr(options.Action),$(this).val()) */
ga("send","event",options.Category,$(this).attr(options.Action),$(this).val())
});
var checkbox = $(options.Forms+' input:checkbox:checked');
jQuery.each(checkbox, function(i,val) {
/* console.log("send","event",options.Category,$(this).attr(options.Action),$(this).val()) */
ga("send","event",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