Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Recording clicks and keystrokes to a csv

I'm attempting to make a Chrome extension that records the number of clicks, keystrokes, and time spent within a certain period of time on a given website (e.g., 45 clicks, 296 keystrokes, and 129 minutes spent on Facebook within one week). I've never coded before and the course I'm writing this code for did not cover Chrome extensions.

So far, I've figured out how to make a simple message appear in the console log when I click the webpage (code given below), but that's about it. How would I export the number of clicks to a .csv?

manifest.json

    "name": "Social Media Consumption Tracker",
    "version": "1.0",
    "manifest_version": 2,
    "content_scripts": [
        {
            "matches": ["https://www.facebook.com/*",
            "http://www.facebook.com/*"],
            "js": ["content.js"]
        }
    ],
  "permissions": ["tabs"]
}

content.js

document.addEventListener("click", e=> {
    console.log("Hey there")
})

Thank you in advance for your help.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I would suggest sending what you have been recording (the clicks and actions) to the background.js file and manipulating it you can do that using chrome.runtime.send messages and chrome.runtime.onMessage` Then after that, generate a download link inside your extension popup to allow the user to download the CSV (you can generate the file the background file)

about 4 years ago · Juan Pablo Isaza Report

0

I think what you need for tracking clicks is the chrome.storage api and Maps

  1. Add your eventListeners for the events you want to track.
  2. When one event you track is fired:

var currentDomain = new URL(location.href).hostname;

document.addEventListener("click", e=> {
    increaseEventCounter("click");
})

function increaseEventCounter(event) {

  chrome.storage.local.get(['youNameIt'],(result) => {
      let youNameIt = result.youNameIt;
      let currentWebsiteEventCounter = youNameIt.get(currentDomain).get(event);
      youNameIt.get(currentDomain).set(event, currentWebsiteEventCounter + 1);

      chrome.storage.local.set({'youNameIt': youNameIt});
  }
  
}

I think storage won´t keep the type of youNameIt, so you need to find a way to cast it again to Map<String,Map<String,Int>>.

  1. Another function which adds new Websites to youNameIt with the counter of every Event you track set to 0.

  2. Search stackOverflow on how to track timeSpend on different Websites, i´m sure there are already answers for that.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!