문제

I'm working on a single page app that will probably fire more than 1 conversion per pageload.

I need to fire the google conversion snippet, so I assumed that I could throw it in at run time. The snippet looks something like this:

<script type="text/javascript">
        /* <![CDATA[ */
        var google_conversion_id = XXXXXXXX;
        var google_conversion_language = "en";
        var google_conversion_format = "2";
        var google_conversion_color = "ffffff";
        var google_conversion_label = "XXXXXXXXXXXXXXX";
        var google_conversion_value = 25.00;
        /* ]]> */
        </script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
        </script>

I have been using javascript to insert the snippet when a conversion has fired. I'm doing it like this:

function(id,url,content){
        // add script
        var script   = document.createElement("script");
        script.type  = "text/javascript";
        if(url) script.src   = url;
        if(content) script.text = content;
        var bucket = document.getElementById(id);
        bucket.appendChild(script);

        debugger;

    }

This works in all the browsers I've tried it in, except safari.

In safari, when the 2nd script tag is added, the entire body tag's content is replaced with a google iFrame. The whole dom is nuked in fact. The head's content is wiped out as well.

What the hell is happening in that google script, and how do I insert this without everything blowing up?!?

Update:

Looks like for some reason safari didn't like the way I was adding the script. To fix this, I added bucket.innerHTML = '' below the debugger line and it worked great in Safari. Unfortunately, that caused FF 3.6 to do what safari was previously doing and nuke the DOM.

To make it even more complicated, it seems AdWords was rejecting these conversions or something, they don't show up on the reporting end when injected to the page.

My current approach is to use htaccess and a little string parsing to generate a page with nothing but the conversion snippet on it, and iFrame it in. I'll report back on that.

도움이 되었습니까?

해결책

Perhaps it might be easier to insert the Google Ads via an iFrame?

Such as like this:

<iframe src="/documents/adsense.htm" width="728px" height="90px" frameborder="0" marginwidth ="0px" marginheight="0px" scrolling="no"></iframe>

iFrame contains:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Google Adsense</title>
<base target="_parent">
</head>
<body>
<!--insert Google Adsense Code Here-->
</body>
</html>

Google will still know and track the parent page.

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