Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda