Google转化跟踪成功回调

Google Conversion tracking success callback

我在 ajax 调用成功时调用 google 转化跟踪代码。 我必须在 ajax 成功时更改 window 位置并同时跟踪转换。

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

我的代码如下:

当我这样做时跟踪有效:

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";
            }
        }
    }
}

回答我自己的问题:

您可以在 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";
  }
 });