Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

A simple Go service for getting the accepted languages of a browser as a JavaScript Object.

Notifications You must be signed in to change notification settings

leighmcculloch/visitor.json

Repository files navigation

visitor.json

Get information about your visitor in a simple JavaScript Object.

{
  "acceptedLanguages": [
    "pt-BR",
    "pt",
    "en-US",
    "en"
  ]
}

Usage

Simple

<script src="https://example.com/js"></script>
<script>
  console.log(window.visitor.acceptedLanguages);
</script>

Simple Async

<script>
  function visitorLoaded(visitor) {
    console.log(visitor.acceptedLanguages);
  }
</script>
<script src="https://example.com/jsonp?callback=visitorLoaded" async="async"></script>

Ajax

Using jQuery it would look like the following, but you can use whichever framework or non-framework you please.

$.ajax('https://example.com/json').done(function(data) {
  console.log(data.acceptedLanguages)
});

Why

Originally created for greatstories.org, a static website that has no backend and but is viewable in multiple languages. The website needed to know the user's preferred languages to make accurate recommendations.

Abandoned

Abandoned when I realized I could use a series of simple tests to get the same information in JavaScript. I now use language.js.

Deploy to PivotalWS

The project contains a manifest.yml and can be deployed to CloudFounder/PivotalWS using cf push.

Deploy to Heroku

The project contains a Procfile and can be deployed to Heroku out-of-the-box.

About

A simple Go service for getting the accepted languages of a browser as a JavaScript Object.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published