Google AdWords转换服务问题-异步转换代码 [英] Google AdWords Conversion Services Issue - Asynchronous Conversion Code

查看:128
本文介绍了Google AdWords转换服务问题-异步转换代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未在网站上实施过Google Adwords,因此如果我对"lingo"不正​​确,请随时进行纠正.

I have never implemented Google Adwords onto a site, so if I am incorrect with the 'lingo', please feel free to correct me.

我正在一个拥有其Google AdWord广告系列之一着陆页的网站上.在此页面上,有一个表格,该表格在处理后会带您到另一页,说谢谢您的请求...".我已删除它并用PHP和Javascript重写了它,以防止页面刷新或重定向.

I am working on a site that has a landing page for one of their Google AdWord campaigns. On this page there is a form, which when processed, takes you to another page to say 'Thank you for your request...'. I have removed this and rewritten it in PHP and Javascript to prevent the page from refreshing or redirecting.

我遇到的问题是,在谢谢"页面上,Google代码略有不同,并且在页面加载时执行. 我的问题是,如何在不重新加载页面的情况下重新执行具有不同变量的转换代码?有为此的Google脚本吗?

The problem I have is that on the 'thank you' page, the Google code is slightly different and is executed on the loading of the page. My question is, how can I re-execute the conversion code with different variables without re-loading the page? Is there a Google script for this?

是否要删除脚本标记,然后再次放置它以重新执行脚本?

这是我当前拥有的代码(在提交表单之前):

This is the code I currently have (before the form submission):

<!-- Google Code for Company Remarketing List Remarketing List -->
<script type="text/javascript">
    /* <![CDATA[ */
    var google_conversion_id = 000000;
    var google_conversion_language = "en";
    var google_conversion_format = "3";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "abcdefg";
    var google_conversion_value = 0;
    /* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script>
<noscript>
    <div style="display:inline;">
        <img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/000000/?label=abcdefg&amp;guid=ON&amp;script=0"/>
    </div>
</noscript>

提交表单后需要更改的内容是:

The things that need to be changed after the form submission are:

var google_conversion_id = 111111;
var google_conversion_label = "gfedcba";
"http://www.googleadservices.com/pagead/conversion/gfedcba/?label=111111&amp;guid=ON&amp;script=0

更改变量很容易!困难的部分是让脚本使用新变量重新执行.

任何帮助,不胜感激!

更新

此处发布的答案可能可以解决此问题,但是,我想知道我可以将其他变量与此答案中提到的变量一起提交.它们很容易说明,但我不能确定它们是正确的!

The answer posted here probably solves this question, however, I would like to know how I can submit the other variables with the variables that were mentioned in this answer. They are pretty self explanatory but I cannot be sure they are right!

此外,有人知道我在Google上的实际位置吗?

推荐答案

您不能仅仅重新执行脚本的原因是-您可能已经注意到-是它使用了document.write,因此不应在文档加载后调用.

The reason why you can't just re-execute the script is—as you may have noticed—is that it uses document.write, which should not be called after the document has already loaded.

一种可能的解决方案是如您所述,自行触发GIF请求.如果您确实要重新执行脚本,则可以重定向document.write.

One possible solution is to just fire off the GIF request yourself, as you mentioned. If you really want to re-execute the script, there's the possibility of redirecting document.write.

这是如何完成此操作的一般思路-该片段将放置在将新内容重新加载到页面中的位置.假定您使用jQuery,并且已经将新页面内容加载到$newContent中,并已用class="ajax-exec"标记了在重新加载时需要执行的所有脚本标签.它的作用是直接执行内联脚本,并将jQuery的$.ajax函数与dataType: script结合使用.然后等待所有外部脚本执行完毕,然后将重定向的输出附加到隐藏的div.

Here's the general idea of how this could be done—this fragment would be placed somewhere where you reload new content into your page. It assumes that you use jQuery and have already loaded the new page content into $newContent and have marked all script tags that need to be executed on reload with class="ajax-exec". What it does is to execute inline script directly and use jQuery's $.ajax function with dataType: script. It then waits until all external scripts have executed and appends the redirected output to a hidden div.

这对我们有效,但不提供保修(:

This works for us, but comes without warranty (:

// Execute js from the new content (e.g. AdWords conversions tags).
// We redirect document.write to a string buffer as we're already
// done loading the page at this point.
var buf = '';
var writeMethSave = document.write;
$('div#lazyload-buf').remove();
var done = {};

document.write = function (string) {
        buf += string;
};

$newContent.filter('script.ajax-exec').each(function () {
    var url = $(this).attr('src');
    if (url) {
        // External script.
        done[url] = false;
        $.ajax({
            url: url,
            dataType: "script",
            success: function () {
                done[url] = true;
            }
        });
    } else {
        // Inline script.
        $.globalEval($(this).html());
    }
});

function checkForDone () {
    for (var url in done) {
        if (!done[url]) {
            setTimeout(checkForDone, 25);
            return;
        }
    }
    // All done, restore method and write output to div
    document.write = writeMethSave;
    var $container = $(document.createElement("div"));
    $container.attr('id', 'lazyload-buf');
    $container.hide();
    $(document.body).append($container);  
    $container.html(buf);
};

setTimeout(checkForDone, 25);

这篇关于Google AdWords转换服务问题-异步转换代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆