# DM Visitor Location Notification

DM VLN allows you to display notification for new visitors on a page with location details (country, city) and stats with top 10 countries for that page.

The plugin uses **ipstack.com** to get visitors details based on IP. 
*You will need an API key from ipstack.com in order for it to work.* 

## How it works

On activation the plugin creates a DB table called **dm_visitor_location** with the columns: IP, Time, Continent, Country, Country_Code, City, Post_ID, id. 
The IP is grabbed with a PHP function at the plugin level and passed to the API request to IPStack, returning the Continent, Country, Country_Code and City. 

For that to happen you will need to use `[dm-vln-notification]` on the page you want to show the notification.

The function behind the shortcode will get the IP, check if the IP exists in the DB for the current Post_ID. If the IP doesn't exists associated with the current Post_ID it will save/create it. If the record already exits it will only update the timestamp. 

The record exists if the IP and the Post_ID match. 

This check is done in order to save API requests, only updating the timestamp on the IPs that were already sent via the API request. 

*Example: if the same IP returned to the same Post_ID that it was visited before, we only update the timestamp, we don't create a new record.*
*If that IP visits a different Post_ID, we'll create a new record with the new Post_ID.*

Based on these records we display the notification that someone is on the page with that Post_ID. 

## Shortcodes

Two shortcodes are available for use:
- `[dm-vln-notification]` - this one will check the visitor details and create/update the records and show the notification message.
- `[dm-vln-top-countries]` - this one will show the top 10 countries that visited the page. 

The `[dm-vln-top-countries]` can't provide correct data if `[dm-vln-notification]` was not added to that page at one point. 
Since `[dm-vln-notification]` does the whole operation regarding visitor data display, save and update. 

## Settings

Dashboard page is created using Carbon Fields. In there you can find options for:
- Adding API Key
- Choose the position of the notification
- Style the color scheme for the notification
- Add a Custom notification message for single and multiple users
- Adjust the Notification display time
- Adjust the Frequency of the Ajax call
- Set the seconds for with to check the DB (based on NOW - seconds we decide what users are new/online)
- Pause the API Request
- Select a date and delete DB records previous to that

On deactivation nothing happens with the DB records, but once you delete the plugin via WP Dashboard the plugin DB table will be removed.

### Custom notification message

Custom notification messages can be adjusted using dynamic variables. 
For Single visitor you have:
- `%dm_vln_country%` - displays the country with the flag
- `%dm_vln_city%` - displays the city (it is not 100% accurate).

For Multiple visitors you have:
- `%dm_vln_visitor_number%` - shows the number of visitors
- `%dm_vln_countries%` - displays list of country codes
- `%dm_vln_flags%` - displays list of flags instead of country codes
- `%dm_vln_country_flags%` - displays list of country codes associated with the flag.

You should only use one of the `%dm_vln_countries%`, `%dm_vln_flags%`, `%dm_vln_country_flags%` or it will show you duplicate data.

In all custom message you can use HTML tags.

## Other details

- The IPs are stored in the DB hashed under MD5. 
- Do not set the **Notification Display Time** to be bigger than **Frequency to check for new visitors**. It will cause the notification to overlap.
- **Seconds before current time to check the database** - lets you check for that amount of seconds in the past for new visitors. Try not to change it to some huge values because the notification will not be relevant anymore.
- The flag images are `.svg` files.
- The font family is grabbed from the site, so no font family is added via the plugin

## Screenshots

**Single Visit notification**

![Single Visit](/screenshots/single-visit_thumb.png)

**Multiple Visits notification**

![Multiple Visits](/screenshots/multiple-visits_thumb.png)

**Multiple Visits from same country notification**

![Multiple Visits same country](/screenshots/multiple-visits-same-country_thumb.png)

**Top countries displayed**

![Top Countries](/screenshots/single-visit.png)

## Can I see a live demo?

Sure, you can check it out here [DM VLN](https://apps.devmaverick.com/dm-vln/)