Skip to main content
added 132 characters in body
Source Link
dev7
  • 6.4k
  • 6
  • 36
  • 68

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is becausethat, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. ThisWhile this can be obvious for a link, this will really hurt the user experience when it comes to buttons (that are not a form submit buttons).

Assuming you want to avoid refershing the page on every button click, you will need to implement Ajax. However,Which leads us to the folllowing question - if you are already using javascript and Ajax, why not simply track everything in Javascript from the first place and only communicate with the server when needed?

Client Side Tracking with localStorage:

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

By having the array data in Javascript you can more easily manipulate the DOM and CSS without dependency on the server. (i.e changing a link's text or, href or css if it was already clicked).

Hope this helps!

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is because, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. This will really hurt the user experience.

Assuming you want to avoid refershing the page on every button click, you will need to implement Ajax. However, if you are already using javascript and Ajax, why not simply track everything in Javascript from the first place and only communicate with the server when needed?

Client Side Tracking with localStorage:

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

By having the array data in Javascript you can more easily manipulate the DOM and CSS without dependency on the server. (i.e changing a link's text or href if it was already clicked)

Hope this helps!

I suggest using client side tehcnology such as localStorage or cookies instead.

The main reason is that, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. While this can be obvious for a link, this will really hurt the user experience when it comes to buttons (that are not a form submit buttons).

Assuming you want to avoid refershing the page on every button click, you will need to implement Ajax. Which leads us to the folllowing question - if you are already using javascript and Ajax, why not simply track everything in Javascript from the first place and only communicate with the server when needed?

Client Side Tracking with localStorage:

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

By having the array data in Javascript you can more easily manipulate the DOM and CSS without dependency on the server. (i.e changing a link's text, href or css if it was already clicked).

Hope this helps!

added 186 characters in body
Source Link
dev7
  • 6.4k
  • 6
  • 36
  • 68

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is because, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. This will really hurt the user experience.

OtherwiseAssuming you want to avoid refershing the page on every button click, you will need to implement Ajax. However, but if you are already using javascript to useand Ajax, why not simply track everything in Javascript from the first place and only communicate with the server when needed?

Client Side Tracking with localStorage:

By using localStoragelocalStorage or CookiesCookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

By having the array data in Javascript you can more easily manipulate the DOM and CSS without dependency on the server. (i.e changing a link's text or href if it was already clicked)

Hope this helps!

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is because, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. This will really hurt the user experience.

Otherwise you will need to implement Ajax, but if you are already using javascript to use Ajax, why not simply track everything in Javascript and only communicate with the server when needed?

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

Hope this helps!

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is because, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. This will really hurt the user experience.

Assuming you want to avoid refershing the page on every button click, you will need to implement Ajax. However, if you are already using javascript and Ajax, why not simply track everything in Javascript from the first place and only communicate with the server when needed?

Client Side Tracking with localStorage:

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

By having the array data in Javascript you can more easily manipulate the DOM and CSS without dependency on the server. (i.e changing a link's text or href if it was already clicked)

Hope this helps!

Source Link
dev7
  • 6.4k
  • 6
  • 36
  • 68

I suggest using client side tehcnology such as localStorage or cookies instead.

The main is reason is because, if you are trying to track clicks on buttons and links with PHP, you would need to send a new HTTP request every time so you can track it on your PHP with $_POST or $_GET. This will really hurt the user experience.

Otherwise you will need to implement Ajax, but if you are already using javascript to use Ajax, why not simply track everything in Javascript and only communicate with the server when needed?

By using localStorage or Cookies, you can simply bind events to clicks and save it to an array.

In Javascript/jQuery you can use the following examaple:

$(document).ready(function() { var urls = JSON.parse(localStorage["visited"]) || [];//get the visited urls from local storage or initialize the array if (urls.indexOf(document.URL) == -1) {//if current url does not exist in the array urls.push(document.URL);//add it to the array localStorage["visited"] = JSON.stringify(urls);//save a stringifyed version of the array to local storage } }); 

Hope this helps!