0

我在 ajax 调用成功时调用谷歌转换跟踪代码。我必须在 ajax 成功时更改窗口位置并同时跟踪转换。

有什么方法可以接收转化跟踪成功的回调,以便我可以更改跟踪成功的窗口位置?

我的代码看起来像:

当我这样做时跟踪工作:

var oReq = getXMLHttpRequest();
if (oReq != null) {
    oReq.open("POST", "http://www.example.com/index.php?r=user/create-mobile-user", true);
    oReq.onreadystatechange = function handler() {
        if (oReq.readyState == 4) {
            if (oReq.status == 200) {
                window.google_trackConversion ({
                    google_conversion_id: 946425313,
                    google_conversion_language: "en",
                    google_conversion_format: "3",
                    google_conversion_color: "ffffff",
                    google_conversion_label: "7P62CPrGtl4Q4ZulwwM",
                    google_remarketing_only: false
                });
            }
        }
    }
}

在下面的代码中不起作用:

var oReq = getXMLHttpRequest();
if (oReq != null) {
    oReq.open("POST", "http://www.example.com/index.php?r=user/create-mobile-user", true);
    oReq.onreadystatechange = function handler() {
        if (oReq.readyState == 4) {
            if (oReq.status == 200) {
                window.google_trackConversion ({
                    google_conversion_id: 946425313,
                    google_conversion_language: "en",
                    google_conversion_format: "3",
                    google_conversion_color: "ffffff",
                    google_conversion_label: "7P62CPrGtl4Q4ZulwwM",
                    google_remarketing_only: false
                });
                window.location.href = "http://www.example.com/booking";
            }
        }
    }
}
4

1 回答 1

1

回答我自己的问题:

您可以将 json 中的回调函数传递给 google_trackConversion 函数。

以下是工作代码:

 window.google_trackConversion({
  google_conversion_id: 946425313,
  google_conversion_language: "en",
  google_conversion_format: "3",
  google_conversion_color: "ffffff",
  google_conversion_label: "7P62CPrGtl4Q4ZulwwM",
  google_remarketing_only: false,
  onload_callback: function() {
     window.location.href = "http://www.example.com/booking";
  }
 });
于 2015-08-31T08:55:11.323 回答