如何使用Javascript跟踪出站点击(How To Track Outbound Clicks Using Javascript)
我正在尝试使用此处提供的代码: 在不重定向的情况下ping一个url 。 OP已经要求在不打开多个窗口的情况下ping网址。 我想这样做,但我想实际访问第二个网址,以便我可以跟踪我的服务器分析中的出站点击。
这是我正在尝试的代码:
<a href="javascript:;" onclick="visitPageX()">link</a> function visitPageX() { // send Ajax request to the track URL setTimeout(function() { location.href = 'http://{pageXURL}'; }, 300); }
但是,我不明白我应该把我的“跟踪网址”放在哪里。 这是我的尝试:
<a href="javascript:;" onclick="visitPageX()"><a href="http://externalsite.com/">anchor text</a></a> function visitPageX() { // send Ajax request to the track URL setTimeout(function() { location.href = 'http://externalsite.com/'; }, 300); }
我坚持要放在哪里
http://examplemysite.com/tracking.php?123
这样我就可以计算出站点击次数。 如果您可以帮助我使用此代码,或者提供更好的解决方案来跟踪外出点击而无需使用Google Analytics,我将不胜感激。
非常感谢您的支持。
I am trying to use the code provided here: Make a ping to a url without redirecting. The OP has asked to ping a url without opening multiple windows. I would like to do this, but I want to actually visit a second url so I can track the outbound clicks in my server analytics.
Here's the code I'm trying to make work:
<a href="javascript:;" onclick="visitPageX()">link</a> function visitPageX() { // send Ajax request to the track URL setTimeout(function() { location.href = 'http://{pageXURL}'; }, 300); }
However, I don't understand where I should be putting my "tracking url". Here's my attempt at it:
<a href="javascript:;" onclick="visitPageX()"><a href="http://externalsite.com/">anchor text</a></a> function visitPageX() { // send Ajax request to the track URL setTimeout(function() { location.href = 'http://externalsite.com/'; }, 300); }
I'm stuck at where to put
http://examplemysite.com/tracking.php?123
so that I can count the outbound clicks. I would appreciate it if you could help me get this code working or provide an even better solution to tracking outbound clicks without using Google Analytics.
Your support is very much appreciated.
原文:https://stackoverflow.com/questions/46851955
最满意答案
如果您正在侦听后退按钮,则可以添加以下if语句:
if (document.activeElement == $("#date-selector1")[0]) { /*disable button here, return false etc...*/ }
甚至更好(感谢Jonathan Sampson)
if (document.activeElement.id === "date-selector1") { /*disable button here, return false etc...*/ }
if you're listening for the back button you can add this if statement:
if (document.activeElement == $("#date-selector1")[0]) { /*disable button here, return false etc...*/ }
or even better (Thanks to Jonathan Sampson)
if (document.activeElement.id === "date-selector1") { /*disable button here, return false etc...*/ }
相关问答
更多-
我最近尝试了相同的例子,并能够使其工作。 但主要区别在于我使用了Cordova CLI 。 注意:您需要安装:Apache ANT,JAVA,Android SDK,GIT命令行工具。 前三项也需要在环境路径中正确设置。 这些是我执行的步骤: 下载Node.JS(然后运行命令提示符) npm install -g cordova npm install -g coffee-script cd C:\ cordova create bluetooth com.example.bluetooth bluetoo ...
-
当有多个具有相同名称的元素时,如何删除确切的元素?(How to delete the exact element when there are multiple elements with same name?)[2024-01-04]
如果您对要删除的实际元素有引用,请记住它是多态的Content对象。 因此,您可以使用接受Content引用( Javadoc )的removeContent()方法。 If you have a reference to the actual element you want to remove, remember that it is polymorphically a Content object. So you can use the removeContent() method that acce ... -
Firebug的 Net面板 。 同样,仅在Firefox中,虽然Firebug Lite可能包含此内容,但我不确定。 如果确实如此,那也是如此。 Firebug's Net panel. Again, only in Firefox, although Firebug Lite might include this, I'm not sure. If it does, that'd cover this too.
-
看看媒体课。 http://docs.phonegap.com/en/2.9.0/cordova_media_media.md.html#Media Take a look at the Media class. http://docs.phonegap.com/en/2.9.0/cordova_media_media.md.html#Media
-
如果您正在侦听后退按钮,则可以添加以下if语句: if (document.activeElement == $("#date-selector1")[0]) { /*disable button here, return false etc...*/ } 甚至更好(感谢Jonathan Sampson) if (document.activeElement.id === "date-selector1") { /*disable button here, return false ...
-
你是现货。 电话差距是弥补硬件和您的网络应用程序之间的差距。 如果您未使用列出的任何硬件项目,则无需使用PhoneGap。 Jquery Mobile将是一个不错的选择。 在旁注 - 很快,也不需要PhoneGap! 使用HTML5,您应该能够直接访问大部分硬件。 但是,仍然浏览器仅限于不支持此功能。 (Chrome工作,最新的FF夜间版本,Opera Developer版本可以访问相机/麦克风) You are spot on. Phone gap is for bridging the gap betw ...
-
如果deviceready没有触发,那么问题不在于写入文件 - 而是在于如何设置phonegap应用程序。 您必须在主要活动中导入以下内容: import android.app.Activity; // used to fire deviceready import android.os.Bundle; import org.apache.cordova.*; The issue isn't with writing a file if deviceready isn't firing -- it's ...
-
Jquery查找确切的树元素(Jquery Find exact DOM elements)[2021-12-20]
最好最接近这个: $(document).on('click', '.XAxisrowCheckbox', function () { $(this).closest('td').css('background-color','red'); }); 它读得比parent和next好得多,如果你需要,你也可以链接到find语句。 例如: $(this).closest('td').find('a').css('color','red'); 这基本上是说“沿着dom树工作,直到你发现第一个td包裹点 ... -
尝试使用Component.getLocationOnScreen() 。 Try using Component.getLocationOnScreen().
-
Touchmove与Phonegap(Touchmove with Phonegap)[2020-12-16]
这里的移动safari参考(android基本相同): http://developer.apple.com/library/IOS/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html 你想要的是: var x = event.touches[0].pageX; var y = event.touches[0].pageY; 如果你在Android上运行,你还需要在触摸 ...