2012-07-12 42 views
-3

我的腳本下面的代碼,但由於某些原因,它不工作,請幫助謝謝無法獲取地理位置腳本工作

<script> 
    $.getScript('http://www.geoplugin.net/javascript.gp', function() { 

    $location = geoplugin_countryCode(); 
$location2 = geoplugin_continentCode();   



    if($location == "CA" || $location == "US" || $location2 == "EU" || $location2 == "DE" || $location2 == "FR" || $location2 == "GB") { 
    alert($location); 
     var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-9240923-27']); 
_gaq.push(['_trackPageview']); 

(function() { 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})(); 

    } else { 

     var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-9240923-27']); 
_gaq.push(['_trackPageview']); 

(function() { 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})(); 
    } 

}); 



     </script> 
+0

你是什麼意思,它不起作用?發生了什麼,你期望會發生什麼? – 2012-07-12 08:31:06

+0

它不顯示在谷歌分析 – Chriswede 2012-07-12 08:35:59

+0

我不知道我明白你想在這裏完成。您正在if和else子句中加載分析?爲什麼不在if語句之後呢呢?爲什麼你要在getScript的成功回調中加載Google Analytics? – 2012-07-12 08:40:31

回答

2

這不是一個正確的答案,因爲它目前還不清楚什麼實際問題是,但要向OP解釋,我會將其作爲答案發布。

$.getScript('http://www.geoplugin.net/javascript.gp', function() { 

    $location = geoplugin_countryCode(); 
    $location2 = geoplugin_continentCode();   

    if($location == "CA" || $location == "US" || $location2 == "EU" || $location2 == "DE" || $location2 == "FR" || $location2 == "GB") { 
     alert($location); 
    } 
}); 

/* 
* I'm not sure what you want to accomplish 
* with loading Google Analytics within the success 
* callback of getScript, so I moved it out here until that is clarified. 
*/ 
var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-9240923-27']); 
_gaq.push(['_trackPageview']); 

(function() { 
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
})();