Google Analytics in ADF using javascript
2013-12-06 17:46
399 查看
Avoid create the ga.js duplicate.
js file googletracker.js
function startTrace(){
(function() {
var scripts= document.getElementsByTagName('script');
var path= scripts[0].src.split("/")[3];
if(path != "ga.js"){
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{
s = document.getElementsByTagName('script')[0]; s.remove();
s = document.getElementsByTagName('script')[0];//get script[0] again
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';
s.parentNode.insertBefore(ga, s);
}
})();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['_trackPageview']);
alert('inside function: ' + document.title);
}
In the templat page add
<af:resource source="/googletracker.js" type="javascript"/>
<af:resource type="javascript">
startTrace();
</af:resource>
js file googletracker.js
function startTrace(){
(function() {
var scripts= document.getElementsByTagName('script');
var path= scripts[0].src.split("/")[3];
if(path != "ga.js"){
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{
s = document.getElementsByTagName('script')[0]; s.remove();
s = document.getElementsByTagName('script')[0];//get script[0] again
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';
s.parentNode.insertBefore(ga, s);
}
})();
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['_trackPageview']);
alert('inside function: ' + document.title);
}
In the templat page add
<af:resource source="/googletracker.js" type="javascript"/>
<af:resource type="javascript">
startTrace();
</af:resource>
相关文章推荐
- Control WRL embedded in html using Javascript
- Get Form type using javascript in CRM 2011
- Parameter passing using Javascript+actionFunction in visualforce
- Creating Vista Gadgets: Using HTML, CSS and JavaScript with Examples in RSS, Ajax, ActiveX (COM) and
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0
- Using Google Maps in Android
- Get Form type using javascript in CRM 2011
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0
- Build Google IG like Ajax Start Page in 7 days using ASP.NET Ajax and .NET 3.0
- A web-scraping framework written in Javascript, using PhantomJS and jQuery pjscrape
- Google Analytics in IOS(一)—— 什么是谷歌分析
- Enable lazyloading in javascript while using extjs
- Coding in the Shade: Using Eclipse with Google Data APIs
- Disable Back Button in Browser using JavaScript
- Convert objects to JSON in C# using JavaScriptSerializer
- Using Visual Studio to Debug JavaScript in IE
- Using the JavaScript console in Visual Studio Code
- Using Visual Studio to Debug JavaScript in IE
- Google Analytics in IOS(四)—— 高级配置
- Accessing List Data using the JavaScript Client OM and displaying in a Dialog