【问题标题】:Page get redirected on Google Adwords Conversion Tracking页面在 Google Adwords 转化跟踪上被重定向
【发布时间】:2017-07-13 12:18:03
【问题描述】:

我有一个表单,人们提交数据并使用 ajax 将数据发送到服务器。我已将此设置为 Google Adwords 中的转换。下面是我用过的代码。

问题是,当用户提交表单时,在收到响应后,它会重定向回我给出的 URL。我不想重定向!!

(提交的数据使用Vue-resource,因为这个项目是在VueJS中)

submit() {
  let self = this
  this.$validator.validateAll().then(success => {
    if (!success) {
      return;
    }
    document.getElementById("submitQuote").value = "Submitting...";
    this.$http.post(store.state.url+'api/submit_quote.php', {
        formData: store.state.formData
      })
      .then(response => {
        console.log(response.data)
        this.submitted = true
        self.reference_id = response.data
        goog_report_conversion('https://www.example.com/') //report Google that a conversion has occured
      });
  });
}

Google 提供的代码

<!-- Google Code for Add to Cart Conversion Page
    In your html page, add the snippet and call goog_report_conversion
    when someone clicks on the chosen link or button. -->
    <script type="text/javascript">
     /* <![CDATA[ */
    goog_snippet_vars = function() {
      var w = window;
      w.google_conversion_id = 12345678;
      w.google_conversion_label = "abcDeFGHIJklmN0PQ";
      w.google_conversion_value = 13.00;
      w.google_conversion_currency = "USD";
      w.google_remarketing_only = false;
    }
    // DO NOT CHANGE THE CODE BELOW.
    goog_report_conversion = function(url) {
      goog_snippet_vars();
      window.google_conversion_format = "3";
      var opt = new Object();
      opt.onload_callback = function() {
      if (typeof(url) != 'undefined') {
        window.location = url;
      }
    }
    var conv_handler = window['google_trackConversion'];
    if (typeof(conv_handler) == 'function') {
      conv_handler(opt);
      }
        }
    /* ]]> */
    </script>
    <script type="text/javascript"
    src="//www.googleadservices.com/pagead/conversion_async.js">
    </script>                                                  

【问题讨论】:

    标签: javascript ajax vue.js google-ads-api vue-resource


    【解决方案1】:

    只是不要提供指向goog_report_conversion 的重定向 URL,即不带参数调用它。

    重定向是有条件的:

    if (typeof(url) != 'undefined') {
        window.location = url;
    }
    

    【讨论】:

    • 但是为什么google要在这段代码上方写“//不要更改下面的代码。”?
    • 我不建议更改该代码,而是在不带参数的情况下调用goog_report_conversion()。为了回答您的问题,这可能是为了降低非技术用户在将脚本插入网页时无意中使脚本失效的可能性。
    • 如果在不带参数的情况下调用goog_report_conversion(),adwords能否获取到转化页面的url?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    相关资源
    最近更新 更多