문제

Can I have more than one google adwords conversion label on a single web page? It looks like the javascript variables would just overwrite each other.

What if I remove the javascript variables and just keep the noscript link?

conversion 1

var google_conversion_id = 123;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "666666";
var google_conversion_label = "abc";
var google_conversion_value = 0;

conversion 2:

var google_conversion_id = 456;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "000000";
var google_conversion_label = "def";
var google_conversion_value = 0;

followed by script tag:

<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script>

and sample noscript tags:

<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/..."/>

</div>
도움이 되었습니까?

해결책

What worked for us was just including the entire block of code (including the <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js"></script> tag itself) twice. Because the script tag contains code which is executed immediately, including it twice will cause it to execute twice - each time using the variables declared immediately before it.

다른 팁

The Javascript function.

var goog_report = function(id, label, value){
    if(typeof(value)==='undefined') value = 0;
    var base_url = 'www.googleadservices.com/pagead/conversion/';
    var img = new Image(1,1);
    img.src = base_url + id +'/?label='+label+'&value='+ value +'&script=0';
};

Set your Google variables.

var goog_id = 1234;
var goog_label = 'xyz';
var goog_value = 10.99;

Example 1: Call within HTML.

<script>
goog_report(goog_id, goog_label, goog_value);
</script>

Example 2: Call within an event handler.

<script>
var handleSomeEvent = function(evt) {
    goog_report(good_id, goog_label, goog_value);
};
</script>

Example 3: Call after jQuery Ajax success call.

<script>
$.ajax({
    type: "POST",
    url: "/charge/",
    data: $('form').serialize(),
    success: function(data) {
        goog_report_purchase(goog_id, goog_label, data.charge_amount);
    }
});
</script>

Example 4: Hard-coded OnClick event on Anchor Element

<a href="javascript:;" onclick="goog_report(1234, 'xyz', 10.99)">Boom! Conversion.</a>

Note that as of October 2017, you can (and should) use Google's new gtag.js, which is a new web tagging library that replaces the older AdWords website conversion tracking and remarketing tags.

gtag.js allows you to send tracking data to multiple AdWords accounts by adding a call to the ‘config’ command for every account you’ll be using, specifying each account’s conversion ID:

<!-- Global Site Tag (gtag.js) - Google AdWords: GOOGLE_CONVERSION_ID_1 -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-GOOGLE_CONVERSION_ID_1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'AW-GOOGLE_CONVERSION_ID_1');
  gtag('config', 'AW-GOOGLE_CONVERSION_ID_2');
</script>

This is the pattern that modern solutions should follow.

You need to insert the tag below each group of variables

// first slot of variables

// second slot of variables // you don't need 'var' statement anymore

Or you insert on only the content of the noscript tag, but without (is mostly as good as the javascript tag)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top