Giter Site home page Giter Site logo

kuzeyardabulut / aws-visitor-counter Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 0.0 30 KB

Easily count site visitors with AWS Lambda and display it on your site.

Python 100.00%
aws aws-lambda lambda-functions python serverless visitor visitor-counter api-gateway dynamodb lambda cloud-resume-challenge

aws-visitor-counter's Introduction

What Is This?

With this repo, you can save your website visitors number on AWS DynomoDB and you can easily expose as api with AWS Lambda Function. If you want to add visitor number to your website you should use Javascript. In this repo, you will learn how to make visitor counter without using AWS Services.

Creating Services

First you should create an AWS account. After that you need to create a table named VisitorCount from DynamoDB and partition key must be id(String).

image

Than you should edit Item editor like this. After that you should create a Lambda and API Gateway.

Lambda Function

This repo does not explain AWS setup. If you are having problems about setting up AWS Services. Please review the required documents.

First we are going to write a Lambda Function. Then you will install the lambda_function.py. Import or copy everything like this.

image

After that create a Get Method in API Gateway. Connect the API Gateway with DynamoDB. After that you should Deploy API and Enable CORS.

image

If you're making the right adjustments, you need this building.

Usage of HTML and Javascript

In this part, we should add Javascript command in our website code. You should Write this command inside the HTML code.

<script>
    		fetch('https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/beta') // You should change the link.
      		.then(response => response.json())
      		.then((data) => {
        	document.getElementById('visitor_counter').innerText = data.Count
      		})
</script>

With this command now you can call the value.

If you want to write this value to your website, you should add this command to your HTML code.

<span id="visitor_counter" />

After all of that, you can use visitor counter in your website.

You can see an example in here.

aws-visitor-counter's People

Contributors

kuzeyardabulut avatar

Stargazers

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

Watchers

 avatar  avatar

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.