2

I'm a developer for the website Friconix, a collection of free icons. Users can include our JS file on their web pages as explain here : https://friconix.com/start/.

I would like to gather statistics on clients using our tools. How to know, on server side, information on pages (URL or at least domains) that request our JS file ?

It's important to explain that, for decreasing the loading time, the JS file is not dynamically generated. There is no PHP file loaded every time the file is requested. The file is saved in plain text on our server. I wonder if the right solution is not to add something in the .htaccess file ?

Fifi
  • 3,360
  • 2
  • 27
  • 53

2 Answers2

3

Since the script is requested from your server every time a user loads a browser-page you can track who and how often that path is requested.

A simple approach is that it will be present in you request log files. So you can create a script and read your log files every so often.

A second approach is to setup a special rule/location in nginx/apache/which-ever-server-you-are-running

A third approach is to serve the script via CDN that has all these attributes built in (ie. CloudFront)

ege
  • 774
  • 5
  • 19
  • Where is the log file? Not sure our server is configured for logging users. – Fifi Oct 16 '19 at 07:07
  • If it is an apache server there will be an access and an error log file. Usually in /var/log/httpd or /var/log/apache2. Check the access log in this directory to see the format of the log input. Usually it will include the users IP, response status (200 or 304 not modified). Check the apache docs for more specifics. – ege Oct 16 '19 at 07:20
  • I found the log files in /logs in my root folder, perfect answer. Thank you. – Fifi Oct 16 '19 at 19:08
  • @Fifi When you have found an answer to your issue, please mark it as 'solved' – ege Oct 17 '19 at 06:58
3

This can be done via a simplistic REST API call from the script. Thus when your script will load it will call the rest API via an AJAX or XHR call. The request can contain a unique client ID. On the server-side, you can implement a simple API that will accept these requests and store them by extracting the necessary information for analytics.

All the information like domains and IP about the client can be gathered from the API request or requests which will be made from clients page.

Reference - How do I call a JavaScript function on page load?

damitj07
  • 2,689
  • 1
  • 21
  • 40