Every 'up' in my PWA is counted twice

Viewed 23

Hi,

I'm using this code in my PWA, but the 'up' is always counted twice.
I see the same at the dashboard, so the real number of users is only half of the reported number.

<script src="https://cdn.jsdelivr.net/npm/counterapi/dist/counter.browser.min.js"></script>
  <script>	
      const counter = new Counter({ workspace: 'nameofmyworkspace' });
      counter.up('nameofmycounter')
        .then(result => console.log(result.data.up_count))
        .catch(err => console.error(err));	
  </script>
2 Answers

Hi,

are you sure that this code executed ince on your website? Maybe you can debug this my adding 'console.log'.

Hi,

Thanks for the quick answer. Yes, it is only called once. Tested also in the Chrome debugger with a breakpoint. I first thought it was because it was a PWA, but even a small normal html file does the same.

Full code example where it happens:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Test Counter</title>  
</head>
<body>
  <div>Hello</div> 
  <script src="https://cdn.jsdelivr.net/npm/counterapi/dist/counter.browser.min.js"></script>
  <script>	
	const counter = new Counter({ workspace: 'nameofworkspace' });
    counter.up('nameofcounter')
        .then(result => console.log(result.data.up_count))
        .catch(err => console.error(err));	
  </script>  
</body>
</html>