我在我的项目中使用谷歌adword标签。
我已将所有adword数据放在一个单独的js插件文件中,如下所示:
(function ($) {
$.fn._djconversion = function (options) {
var _self = this;
//--default options
var opts = $.extend({
google_conversion_id: 981680506,
google_conversion_language: "en",
google_conversion_format: "3",
google_conversion_color: "ffffff",
google_conversion_label: "aPTpCKjOu2wQ-oKN1AM",
google_remarketing_only: false
}, options);
//--init function
_self.init(function () {
$.getScript('//www.googleadservices.com/pagead/conversion.js');
var image = new Image(1, 1);
image.src = "//www.googleadservices.com/pagead/conversion/" + opts.google_conversion_id + "/?label=" + opts.google_conversion_label + "&guid=ON&script=0";
/* Conversion Tracking End */
});
_self.init();
//make the plugin chainnable with other methods
return _self;
};
})(jQuery);
现在我们在按钮点击事件上调用该方法,如下所示:
$(document).on('click','#btnSubmit',function(){
var gopts = {
google_conversion_label: "aPTpCKjOu2wQ-oKN1AM"
};
$("body")._djconversion(gopts);
});