我需要在myOfLineFunction
运行时触发下面的Google转换脚本。如何将Google变量和Google的conversion.js集成到myOfLineFunction
中来执行此操作?
发送离线消息时运行的功能:
<script>
myOfLineFunction('api.chat.onOfflineMessageToOperator', function(event) {
("sent_an_offline_message");
});
</script>
当上述myOfLineFunction
运行时,如何运行以下Google变量?
<script>
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "abcdefghijklmnop";
var google_conversion_value = 0;
var google_remarketing_only = false;
</script>
也包括这个脚本?
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion.js"></script>
编辑6/10/14
这个答案似乎是要走的路:(来自How to track a Google Adwords conversion onclick?)
使用:
<script type="text/javascript">
function trackConv(google_conversion_id,google_conversion_label) {
var image = new Image(1,1);
image.src = "http://www.googleadservices.com/pagead/
conversion/"+google_conversion_id+"/?label="+google_conversion_label
+"&script=0"; }
</script>
跟踪这样的链接:
<a onclick="trackConv(1234567890,"LQV8CNq6RxCKlPbvAw");"
href="http://somelink.com">Link</a>
那么如何在我的myOfLineFunction
答案 0 :(得分:1)
我将免责声明我在此处提供的解决方案很脏,但如果您仅限于在当前页面上运行脚本,那么它是唯一可以提出的解决方案。
您的问题是内联Google转换像素使用document.write,因此当浏览器呈现时,它必须包含在页面中。我们可以通过创建子窗口并在其中运行脚本来解决此问题。没有办法隐藏窗口(脏部分),但是我们可以制作尽可能小的模糊信息,并且一旦Google像素有时间加载就关闭它:
function fireGcPixel() {
var script = '<scr' + 'ipt>';
script += 'var google_conversion_id = "xxxxxxxxxx";';
script += 'var google_conversion_language = "en";';
script += 'var google_conversion_format = "2";';
script += 'var google_conversion_color = "ffffff";';
script += 'var google_conversion_label = "abcdefghijklmnop";';
script += 'var google_conversion_value = 0;';
script += 'var google_remarketing_only = false;';
script += '</scr' + 'ipt>';
script += '<scr' + 'ipt type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></scr' + 'ipt>';
var win, doc;
win = window.open('', 'dialog', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10000, top=10000,width=1,height=1, visible=none');
win.onload = function(){alert("loaded");};
doc = win.document;
doc.write(script);
doc.close();
win.blur();
};
现在,如果您控制域,则有一些更清洁的解决方案:
希望这有帮助。
答案 1 :(得分:1)
试试这个:
function trackConv(google_conversion_id,google_conversion_label) {
var image = new Image(1,1);
image.src = "http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?label="+google_conversion_label+"&script=0";
}
myOfLineFunction('api.chat.onOfflineMessageToOperator', function(event) {
trackConv(1234567890,"LQV8CNq6RxCKlPbvAw");
});