PHP Classes
elePHPant
Icontem

File: docs/tracker.js

Recommend this page to a friend!
  Classes of Barton Phillips  >  PHP Site Class  >  docs/tracker.js  >  Download  
File: docs/tracker.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Site Class
Create database driven Web sites
Author: By
Last change: Changed the meaning of 'myUri' in 'mysitemap.json'. It can now be a string or an array. This impacts 'myIp' in SiteClass and the the files in
the docs directory. The 'myIp' can be a string or an array. The 'myIp' is checked in the 'trackbots' and 'isMe' methods.
beacon.php and tracker.php are from bartonlp.com/ and have changes in them.
tracker.js now has 'beaconUri' which is set with LocalPath if it is set.
modified: docs/beacon.php
modified: docs/robots.php
modified: docs/sitemap.php
modified: docs/tracker.js
modified: docs/tracker.php
modified: includes/SiteClass.class.php
Date: 10 months ago
Size: 3,730 bytes
 

Contents

Class file image Download
// BLP 2014-03-06 -- track user activity

// Kluge! For weewx only. LocalPath is defined in the head.i.php file
// as '/weewx'. Otherwise LocalPath is always 'undefined' and we set
// it to ''.

if(typeof LocalPath == 'undefined') {
  var LocalPath = '';
}

// Post a AjaxMsg. Local function

function postAjaxMsg(msg) {
  msg = "NEW: " + msg;
  $.ajax({
    url: trackerUrl,
    data: {page: 'ajaxmsg', ipagent: true, msg: msg},
    type: 'post',
    success: function(data) {
           console.log(data);
         },
         error: function(err) {
           console.log(err);
         }
  });             
}

// Some of the bartonlp.com banner.i.php files have not been modified
// to use 'logo' and still use 'blpimg' and have the head.i.php still
// setting 'blpimg' in a script. BUT that should be OK as if there is
// NO 'logo' nothing happens. I should probably fix this at some point.

jQuery(document).ready(function($) {
  console.log("LocalPath: " +LocalPath);
  $("#logo").attr('src', LocalPath +"/tracker.php?page=script&id="+lastId);
});

// The rest of this is for everybody!

(function($) {
  console.log("lastId: " + lastId);
  
  var trackerUrl = LocalPath + "/tracker.php";
  var beaconUrl = LocalPath + "/beacon.php";
  
  // 'start' is done weather or not 'load' happens.

  $.ajax({
    url: trackerUrl,
    data: {page: 'start', id: lastId },
    type: 'post',
    success: function(data) {
      console.log(data);
    },
    error: function(err) {
      console.log(err);
    }
  });
  
  $(window).on("load", function(e) {
    $.ajax({
      url: trackerUrl,
      data: {page: 'load', 'id': lastId},
      type: 'post',
      success: function(data) {
        console.log(data);
      },
      error: function(err) {
        console.log(err);
      }
    });
  });

  $(window).on('beforeunload ',function() {
    $.ajax({
      url: trackerUrl,
      data: {page: 'beforeunload', id: lastId },
      type: 'post',
      async: false,
      success: function(data) {
        console.log(data);
      },
      error: function(err) {
        console.log(err);
      }
    });
  });
  
  $(window).on("unload", function(e) {
    $.ajax({
      url: trackerUrl,
      data: {page: 'unload', id: lastId },
      type: 'post',
      async: false,
      success: function(data) {
        console.log(data);
      },
      error: function(err) {
        console.log(err);
      }
    });
  });

  $(window).on("pagehide", function(e) {
    $.ajax({
      url: trackerUrl,
      data: {page: 'pagehide', id: lastId },
      type: 'post',
      async: false,
      success: function(data) {
        console.log(data);
      },
      error: function(err) {
        console.log(err);
      }
    });
  });

  // We will use beacon also

  if(navigator.sendBeacon) {
    $(window).on("pagehide", function() {
      navigator.sendBeacon(beaconUrl, JSON.stringify({'id':lastId, 'which': 1}));
    });

    $(window).on("unload", function() {
      navigator.sendBeacon(beaconUrl, JSON.stringify({'id':lastId, 'which': 2}));
    });

    $(window).on('beforeunload ',function() {
      navigator.sendBeacon(beaconUrl, JSON.stringify({'id':lastId, 'which': 4}));    
    });
  } else {
    var msg = "NEW: Beacon NOT SUPPORTED";
    console.log(msg);
  }

  // Now lets try a timer to update the endtime

  var $time = 5000,
  $cnt = 0;

  function runtimer() {
    if($cnt++ < 20) {
      $time += 10000;
    }
    $.ajax({
      url: trackerUrl,
      data: {page: 'timer', id: lastId },
      type: 'post',
      success: function(data) {
        console.log(data);
        setTimeout(runtimer, $time)
      },
      error: function(err) {
        console.log(err);
      }
    });
  }

  runtimer();
})(jQuery);