2012-04-05 4 views
2

Google 애드워즈를 사이트에 구현 한 적이 없으므로 '용어'가 올바르지 않으면 언제든지 저를 고칠 수 있습니다.Google 애드워즈 전환 서비스 문제 - 비동기 전환 코드

Google AdWord 캠페인 중 하나에 대한 방문 페이지가있는 사이트에서 작업하고 있습니다. 이 페이지에는 양식이 있습니다.이 양식은 처리 될 때 '귀하의 요청에 감사드립니다 ...'라는 다른 페이지로 안내합니다. 내가 이것을 제거하고 페이지를 새로 고치거나 리디렉션하지 못하도록 PHP 및 Javascript로 다시 작성했습니다.

내가 가진 문제는 '감사합니다'페이지에서 Google 코드가 약간 다르고 페이지로드시 실행된다는 것입니다. 제 질문은 페이지를 다시로드하지 않고도 다른 변수를 사용하여 변환 코드를 어떻게 다시 실행할 수 있습니까? 이를위한 Google 스크립트가 있습니까?

스크립트 태그를 제거한 다음 스크립트를 다시 실행하면 스크립트가 다시 실행됩니까?

<!-- 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> 

양식 제출 후 변경해야 할 일들은 다음과 같습니다 :

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 

변수를 변경

은 (양식 제출 전) 내가 현재 가지고있는 코드입니다 간단합니다! 어려운 부분은 새 변수로 스크립트를 다시 실행하는 것입니다.

많은 도움을 주셨습니다.

UPDATE 대답은 here을 게시

아마 그러나, 나는이 답변에서 언급 한 변수를 다른 변수를 제출하는 방법을 알고 싶습니다,이 문제를 해결합니다. 그들은 꽤 자명하지만 나는 그들이 옳다는 것을 확신 할 수 없다!

또한 누구나 Google에서 실제로이 지침을 볼 수있는 곳을 알고 있습니까?

답변

1

스크립트를 다시 실행할 수없는 이유는 - 이미 알고있는 것처럼 document.write을 사용하기 때문에 문서가 이미로드 된 후에 호출하면 안됩니다.

하나의 가능한 해결책은 언급 한대로 GIF 요청을 직접 시작하는 것입니다. 스크립트를 다시 실행하려면 document.write을 리디렉션 할 수 있습니다.

여기에 어떻게 할 수 있는지에 대한 일반적인 개념이 있습니다.이 조각은 새 콘텐츠를 페이지에 다시로드하는 곳에 배치됩니다. 여기서는 jQuery를 사용하고 이미 새 페이지 내용을 $newContent에로드하고 다시로드 할 때 실행해야하는 모든 스크립트 태그를 class="ajax-exec"으로 표시했다고 가정합니다. 인라인 스크립트를 직접 실행하고 jQuery의 $.ajax 함수를 dataType: script과 함께 사용하면됩니다. 그런 다음 모든 외부 스크립트가 실행될 때까지 대기하고 리디렉션 된 출력을 숨겨진 div에 추가합니다.

우리를 위해 작동하지만, 보증 (없이 제공 :

// 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);