Coder Social home page Coder Social logo

brentvollebregt / hit-counter Goto Github PK

View Code? Open in Web Editor NEW
135.0 7.0 44.0 101 KB

Easily count hits ๐Ÿ“ˆ on a website by requesting a SVG displaying hit count ๐ŸŽฏ

License: MIT License

Python 60.57% HTML 38.25% Dockerfile 1.17%
view-counter counter visitor-counter

hit-counter's Introduction

Let's get right onto it!

Hi there ๐Ÿ‘‹, it's great to see you! ๐Ÿ˜€

  • ๐Ÿ”ญ I'm a software developer from New Zealand (currently in Wellington)
  • โš—๏ธ A lover of science, heavy machinery, and software development
  • ๐Ÿ“ซ Depending on what you're wanting, the best way to reach me is:
    • Help on a post / video I made: Comment on the post / video
    • Anything else: Email me
  • โšก I commonly use TypeScript, React, .NET, Python and typically do full-stack development

You can also find me at ...

  • ๐ŸŒ nitratine.net: where I write small posts on how to do stuff I'll probably forget later or just want to show off.
  • ๐ŸŽฅ YouTube/PyTutorials: where I make medium-level Python tutorials on focused topics.

Also, here is a small portfolio of my favourite projects ๐Ÿ˜Ž


react typescript python nodejs sqlite dotnet flask

android azure bash bootstrap csharp css3 d3js express gatsby git heroku html5 java javascript Microsoft SQL Server qt redux


๐Ÿ“บ Latest YouTube Videos

โžก๏ธ more videos...

๐Ÿ“• Latest Blog Posts

โžก๏ธ more blog posts...

hit-counter's People

Contributors

blakedrumm avatar brentvollebregt avatar muety avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hit-counter's Issues

How does counting for another site work?

Thanks for this nice project. I'm just a little confused regarding "Getting a Count For a Site That Isn't Me". I want to count the visit for a github.io page, but display the count in the corresponding repo. Do I need to include any code in the webpage for it to be counted? If not, how does the counting server know about visits to that page?

Only one hit per ip

Re-requesting the same svg url with same ip should imo not increment the counter.

Deprecated Usage Examples

When copying and pasting the javascript demo code for Getting the Count Raw my browser gives following warning in the console:

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

I think updating the example to use asynchronous JS would be good long-term.

Thankyou! Such a cool idea!

So I had pretty much this exact idea a few months ago, and am glad I didn't try to implement it (yours is much better). I was going to try to dynamically create PNGs (which is much sillier and harder than SVGs), and I didn't think of using an anti-refresh system too!

Just wanted to thank you for creating this ๐Ÿ‘Œ

proxy not supported

Hi, this is a really good tool. But it seems that your domain does not support proxy visit?

image

Hosting on heroku

Pythonanywhere had a very bad performance in the region I'm living (South Asia) so I had to deploy this on heroku for a better performance. The API request time for pythonanywhere ranged from 2-4 seconds, while heroku gives me sub 500ms response times. The problem is that heroku doesn't support persistent filesystem in free tier so I had to patch the code to work with postgres as it is available in heroku free tier.

My fork with postgres settings is here: https://github.com/zubair-temi/hit-counter

Should I open a pull request to this repo to merge these changes? Maybe you can keep it in a separate branch. What do you think?

I'd also update the README with heroku + postgres deployment instructions if you're willing to merge the changes.

How to install

I am pretty new to Python and do not really understand where to put the files. I want to use it at my own server, let's say: www.example.com
The web files are saved in /var/www/html/myExample/ where myExample is the root directory
of example.com. I have the python files in this directory, too and can successfully start the server.py
I put your template index.html into /var/www/html/myExample/ but I suppose that is not enough??

Ajax request makes the count continuously increasing

Hello,

I don't know if i'm miss-using your plugin or if it's me but given this code:

/**
 * Replace target element inner html
 * @param {*} elementId 
 * @param {*} text 
 */
function replaceTextInElementById(elementId, text){
  document.getElementById(elementId).innerHTML = text;
};

/**
 * Make ajax request and update hits counter
 * @param {*} url 
 * @param {*} elementId 
 */
function updateHitCounterText(url, elementId) {
  return $.ajax('https://hitcounter.pythonanywhere.com/count',{data:{url: url}}).then(hitCount => {
    replaceTextInElementById(elementId, hitCount);
  });
};

const baseUrl = window.origin + '{{ site.baseurl }}';  // i.e: http://localhost:4000/blog
updateHitCounterText(baseUrl, 'total-hits-counter');

The counter is increasing continuously, making it kinda inaccurate. Tbh, that's not much a problem, but since the image is working as intended (not increasing even if you spam refresh), I was wondering if this was normal ;)

Thanks for reading, and thanks for your simple yet very nice work!

Github shows You can't comment at this time.

Since Github shows You can't comment at this time, I try with a new issue.

Ok locally it took more than 30 seconds to see the result, but Github waits only for a few seconds otherwise it displays the link text.
At refreshing my local test in Firefox I see now no result but.

Something went wrong :-( 
This website is hosted by PythonAnywhere, an online hosting environment. 
Something went wrong while trying to load it; please try again later.

Feature request: allow to count files download

Hi.

Your project seems really nice, with clear documentation & clean code (plus I like Python very much !)

I have a need for a self-hosted web app that would allow me to count file downloads for specific files (PDFs & ZIPs).

I the past I used a public instance of dolomon, but it is now closing and I would like to use a more well maintained software, ideally not written in Perl nor PHP.

I searched around on the web, but I could not find any solution that met those requirements.
So maybe that could also be another nice feature of your hit-counter project?

Technically, it could probably be done in Javascript using the current version of hit-counter,
but it isn't documented and I have had bad experiences of messing with download links:
depending on browsers, timing & many other factors sometimes the "hit" may not be properly counted due to the page switch,
or worse, the file download may fail for the user.

Hence I was thinking more about a system like dolomon used, where you "register" a link with hit-counter,
and the app provides a "download link" that acts as a 302 redirect.
This would probably require a DB schema change though.

What do you think about all this ?

No 'Access-Control-Allow-Origin' header is present on the requested resource

My requests started getting blocked from today.

Access to fetch at 'https://hitcounter.pythonanywhere.com/count?url=https%3A%2F%2Fwww.bluprince13.com%2Fblog%2Fchanging-careers-from-aerospace-engineering-to-web-development%2F' from origin 'https://www.bluprince13.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

This is my code:

    const query = `?url=${encodeURIComponent(url)}`
    const path = `https://hitcounter.pythonanywhere.com/count${query}`
    const response = await fetch(path, {
        method: 'GET'
    })
    const hitCount = await response.json()

Feature request: unique visitor count

Hi,
It would be really great if there's a feature of getting total count of unique visitors. If unique visitor by username of github is not possible, what about counting unique visitor by IP-address or anything else maybe? (I think it's possible, I found some sites provide this feature by image, couldn't find any which provide SVG).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.