Javascript Link Tracker

SD_Ryoko

Ultra Cool Member
Reaction score
85
Here I have a javascript that plugs data into a php file.

The php file formats the data and stores it into a mysql database.

Heres the problem: It only stores text links.

Sponsors on GRW are image links. Its ignoring those.

Now, line 28 says 'we don't want to track anything but links'. I commented that line out, but it didn't change anything.
Code:
<script type="text/javascript">
// change the following to the place where you put the linktrack script.
var linktrack="linkstats.php";


// make error proof
function lt_clicker(e) {
  try {
    lt_do_clicker(e);
  } catch (err) {
     //alert("error "+err);
     return true;
  }
  return true;
}
function lt_do_clicker(e) {
// this grabs the link and redirects it to the php site.
  var lt_target = null;
  if (e != null) { 
     lt_target = e.target;
  } else {
     lt_target = window.event.srcElement;
  }
  // move on to our next site

  if (lt_target==null) return true; // can't track a link that doesn't exist

  if (lt_target.nodeName.toUpperCase() != 'A') return true; // don't want to track anything but links.
  if (lt_target.href==null) return true; // if we aren't going anywhere don't track
  var lt_href=lt_target.href;
  var lt_atext="";
  if (lt_target.innerText!=null) {
     lt_atext=lt_target.innerText;
  } else if (lt_target.innerHTML!=null) {
     lt_atext=lt_target.innerHTML;
  } else if (lt_target.text!=null) {
     lt_atext=lt_target.text;
  } else {
    return true; // can't track a link with no description
  }
  if(lt_href==null||lt_atext==null) return true; // once more with feeling.
  if(typeof(lt_href) != 'string') return true;  // not sure what else it could be, except an image.
  // see if the link is off the page
  var lt_host = document.location.hostname.toLowerCase();
  if (lt_host==null||lt_host=="") lt_host="hey hey";
  // if we want to track internal stuff, comment out this next line
  if (lt_href.toLowerCase().indexOf(lt_host)>=0) return true; // don't track in and around site.
  // use the next line to avoid tracking links to some other URL
  if (lt_href.toLowerCase().indexOf("anotherURL")>0) return true;
  lt_href = escape(lt_href);
  lt_atext = escape(lt_atext);
  lt_from=escape(document.location);
  // we have a link. We have to mess with it.
  // it seems the best way to do this is to create a new image, but you can use an iframe
  
  // create the ref to the new image
  try {
     var lt_newurl=linktrack+"?HREF="+lt_href+"&ATEXT="+lt_atext+"&FROM="+lt_from; // sometimes this fails
  } catch (error) {
     var lt_newurl=linktrack+"?HREF="+lt_href+"&ATEXT="+lt_atext;
  }
  //alert (lt_newurl);
  try{ // put it in a try/next to avoid http errors
    var lt_newimg = new Image();
    lt_newimg.src = lt_newurl;
  }catch(err){ 
    return true; 
  }
// the pause that refreshes
  var lt_start = new Date().getTime();
  var lt_stop = lt_start + 500;
  while(lt_start<lt_stop){
    lt_start = new Date().getTime(); // nice tight loop - it might be needed on slow systems
  }
  return true; // let link do his job 
}

// direct code that is executed immediately
   document.onclick=lt_clicker; // this directs links to our code

// end of link tracking

// put this down near the bottom of your page
</script>
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Images don't have any anchors...

Actually, you click on an image, nothing happens, so the click "continues" to its parent element.
Parent being an anchor ("a href="), somthing happens.

Now, commenting out the test on "A" doesn't work, because there's still no anchor...

You could try with:
Code:
if(lt_target.nodeName.toUpperCase() == 'IMG')
	lt_target = lt_target.parentNode;
if(lt_target.nodeName.toUpperCase() != 'A')
{
	return true; // don't want to track anything but links.
}

However, this ony works if the immediate parent element is an anchor, as in
<a href="wherever.html"><img src="myPic.gif"></a>
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Well, then my "fix" will do it.
What could happen? You miss a link... ;)

All in all, however, it would be safer if the page simply had:
a href="linkstats.php?newpage.htm" (or similar)
and would then redirect to "newpage.htm" (or just send that page back).
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
I see... :rolleyes:

Well, TH's OK still holds, I guess. So... what are you waiting for?
Of course, you'll be in for some surprises, but, that's the point, now, isn't it? :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top