-- Basic table from 1.0
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_serverstats` (
  `session_id_person` varchar(50),
  `user_id_person` 	  int NULL DEFAULT 0,
  `customer_name`     varchar(255), 
  `visitdate`         date,
  `visit_timestamp`   int, 
  `visitedpage` 	  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
  `geolocation`       varchar(255), 
  `ip`                varchar(255), 
  `browser`           varchar(255), 
  `os`                varchar(255),
  `device`			  varchar(255) NULL,
  `devicewidth` 	  CHAR(6) NULL,
  `deviceheight` 	  CHAR(6) NULL, 
  `impulse` 		  int NOT NULL DEFAULT 0,
  PRIMARY KEY (`session_id_person` ,  `visitdate` ,  `visitedpage`),
  KEY `session_idx` (`session_id_person`)
) ENGINE=InnoDB CHARACTER SET `utf8`; 
 
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_realstats` (
  `session_id_person` varchar(255) NOT NULL, 
  `nowpage`           varchar(255) NULL, 
  `lastupdate_time`   int NULL, 
  `current_name`  varchar(255) NULL, 
  PRIMARY KEY (`session_id_person`)
) ENGINE=InnoDB CHARACTER SET `utf8`;
 
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_countries_map` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `num_code` smallint NOT NULL,
  `iso1_code` char(2) NOT NULL,
  `name` varchar(80)  NOT NULL,
  `name_caps` varchar(80) NOT NULL,
  `iso3_code` char(3) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB CHARACTER SET `utf8`;
 
INSERT IGNORE INTO `#__realtimeanalytics_countries_map` (`id`, `num_code`, `iso1_code`, `name`, `name_caps`, `iso3_code`) VALUES
(1, 4, 'AF', 'Afghanistan', 'AFGHANISTAN', 'AFG'),
(2, 248, 'AX', 'Aland Islands', 'ALAND ISLANDS', 'ALA'),
(3, 8, 'AL', 'Albania', 'ALBANIA', 'ALB'),
(4, 12, 'DZ', 'Algeria', 'ALGERIA', 'DZA'),
(5, 16, 'AS', 'American Samoa', 'AMERICAN SAMOA', 'ASM'),
(6, 20, 'AD', 'Andorra', 'ANDORRA', 'AND'),
(7, 24, 'AO', 'Angola', 'ANGOLA', 'AGO'),
(8, 660, 'AI', 'Anguilla', 'ANGUILLA', 'AIA'),
(9, 10, 'AQ', 'Antarctica', 'ANTARCTICA', 'ATA'),
(10, 28, 'AG', 'Antigua and Barbuda', 'ANTIGUA AND BARBUDA', 'ATG'),
(11, 32, 'AR', 'Argentina', 'ARGENTINA', 'ARG'),
(12, 51, 'AM', 'Armenia', 'ARMENIA', 'ARM'),
(13, 533, 'AW', 'Aruba', 'ARUBA', 'ABW'),
(14, 36, 'AU', 'Australia', 'AUSTRALIA', 'AUS'),
(15, 40, 'AT', 'Austria', 'AUSTRIA', 'AUT'),
(16, 31, 'AZ', 'Azerbaijan', 'AZERBAIJAN', 'AZE'),
(17, 44, 'BS', 'Bahamas', 'BAHAMAS', 'BHS'),
(18, 48, 'BH', 'Bahrain', 'BAHRAIN', 'BHR'),
(19, 50, 'BD', 'Bangladesh', 'BANGLADESH', 'BGD'),
(20, 52, 'BB', 'Barbados', 'BARBADOS', 'BRB'),
(21, 112, 'BY', 'Belarus', 'BELARUS', 'BLR'),
(22, 56, 'BE', 'Belgium', 'BELGIUM', 'BEL'),
(23, 84, 'BZ', 'Belize', 'BELIZE', 'BLZ'),
(24, 204, 'BJ', 'Benin', 'BENIN', 'BEN'),
(25, 60, 'BM', 'Bermuda', 'BERMUDA', 'BMU'),
(26, 64, 'BT', 'Bhutan', 'BHUTAN', 'BTN'),
(27, 68, 'BO', 'Bolivia', 'BOLIVIA, PLURINATIONAL STATE OF', 'BOL'),
(28, 535, 'BQ', 'Bonaire, Saint Eustatius and Saba', 'BONAIRE, SAINT EUSTATIUS AND SABA', 'BES'),
(29, 70, 'BA', 'Bosnia and Herzegovina', 'BOSNIA AND HERZEGOVINA', 'BIH'),
(30, 72, 'BW', 'Botswana', 'BOTSWANA', 'BWA'),
(31, 74, 'BV', 'Bouvet Island', 'BOUVET ISLAND', 'BVT'),
(32, 76, 'BR', 'Brazil', 'BRAZIL', 'BRA'),
(33, 86, 'IO', 'British Indian Ocean Territory', 'BRITISH INDIAN OCEAN TERRITORY', 'IOT'),
(34, 96, 'BN', 'Brunei Darussalam', 'BRUNEI DARUSSALAM', 'BRN'),
(35, 100, 'BG', 'Bulgaria', 'BULGARIA', 'BGR'),
(36, 854, 'BF', 'Burkina Faso', 'BURKINA FASO', 'BFA'),
(37, 108, 'BI', 'Burundi', 'BURUNDI', 'BDI'),
(38, 116, 'KH', 'Cambodia', 'CAMBODIA', 'KHM'),
(39, 120, 'CM', 'Cameroon', 'CAMEROON', 'CMR'),
(40, 124, 'CA', 'Canada', 'CANADA', 'CAN'),
(41, 132, 'CV', 'Cape Verde', 'CAPE VERDE', 'CPV'),
(42, 136, 'KY', 'Cayman Islands', 'CAYMAN ISLANDS', 'CYM'),
(43, 140, 'CF', 'Central African Republic', 'CENTRAL AFRICAN REPUBLIC', 'CAF'),
(44, 148, 'TD', 'Chad', 'CHAD', 'TCD'),
(45, 152, 'CL', 'Chile', 'CHILE', 'CHL'),
(46, 156, 'CN', 'China', 'CHINA', 'CHN'),
(47, 162, 'CX', 'Christmas Island', 'CHRISTMAS ISLAND', 'CXR'),
(48, 166, 'CC', 'Cocos (Keeling) Islands', 'COCOS (KEELING) ISLANDS', 'CCK'),
(49, 170, 'CO', 'Colombia', 'COLOMBIA', 'COL'),
(50, 174, 'KM', 'Comoros', 'COMOROS', 'COM'),
(51, 178, 'CG', 'Congo', 'CONGO', 'COG'),
(52, 180, 'CD', 'Congo', 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', 'COD'),
(53, 184, 'CK', 'Cook Islands', 'COOK ISLANDS', 'COK'),
(54, 188, 'CR', 'Costa Rica', 'COSTA RICA', 'CRI'),
(55, 384, 'CI', 'Cote D''Ivoire', 'COTE D''IVOIRE', 'CIV'),
(56, 191, 'HR', 'Croatia', 'CROATIA', 'HRV'),
(57, 192, 'CU', 'Cuba', 'CUBA', 'CUB'),
(58, 531, 'CW', 'Curacao', 'CURACAO', 'CUW'),
(59, 196, 'CY', 'Cyprus', 'CYPRUS', 'CYP'),
(60, 203, 'CZ', 'Czech Republic', 'CZECH REPUBLIC', 'CZE'),
(61, 208, 'DK', 'Denmark', 'DENMARK', 'DNK'),
(62, 262, 'DJ', 'Djibouti', 'DJIBOUTI', 'DJI'),
(63, 212, 'DM', 'Dominica', 'DOMINICA', 'DMA'),
(64, 214, 'DO', 'Dominican Republic', 'DOMINICAN REPUBLIC', 'DOM'),
(65, 218, 'EC', 'Ecuador', 'ECUADOR', 'ECU'),
(66, 818, 'EG', 'Egypt', 'EGYPT', 'EGY'),
(67, 222, 'SV', 'El Salvador', 'EL SALVADOR', 'SLV'),
(68, 226, 'GQ', 'Equatorial Guinea', 'EQUATORIAL GUINEA', 'GNQ'),
(69, 232, 'ER', 'Eritrea', 'ERITREA', 'ERI'),
(70, 233, 'EE', 'Estonia', 'ESTONIA', 'EST'),
(71, 231, 'ET', 'Ethiopia', 'ETHIOPIA', 'ETH'),
(72, 238, 'FK', 'Falkland Islands (Malvinas)', 'FALKLAND ISLANDS (MALVINAS)', 'FLK'),
(73, 234, 'FO', 'Faroe Islands', 'FAROE ISLANDS', 'FRO'),
(74, 242, 'FJ', 'Fiji', 'FIJI', 'FJI'),
(75, 246, 'FI', 'Finland', 'FINLAND', 'FIN'),
(76, 250, 'FR', 'France', 'FRANCE', 'FRA'),
(77, 254, 'GF', 'French Guiana', 'FRENCH GUIANA', 'GUF'),
(78, 258, 'PF', 'French Polynesia', 'FRENCH POLYNESIA', 'PYF'),
(79, 260, 'TF', 'French Southern Territories', 'FRENCH SOUTHERN TERRITORIES', 'ATF'),
(80, 266, 'GA', 'Gabon', 'GABON', 'GAB'),
(81, 270, 'GM', 'Gambia', 'GAMBIA', 'GMB'),
(82, 268, 'GE', 'Georgia', 'GEORGIA', 'GEO'),
(83, 276, 'DE', 'Germany', 'GERMANY', 'DEU'),
(84, 288, 'GH', 'Ghana', 'GHANA', 'GHA'),
(85, 292, 'GI', 'Gibraltar', 'GIBRALTAR', 'GIB'),
(86, 300, 'GR', 'Greece', 'GREECE', 'GRC'),
(87, 304, 'GL', 'Greenland', 'GREENLAND', 'GRL'),
(88, 308, 'GD', 'Grenada', 'GRENADA', 'GRD'),
(89, 312, 'GP', 'Guadeloupe', 'GUADELOUPE', 'GLP'),
(90, 316, 'GU', 'Guam', 'GUAM', 'GUM'),
(91, 320, 'GT', 'Guatemala', 'GUATEMALA', 'GTM'),
(92, 831, 'GG', 'Guernsey', 'GUERNSEY', 'GGY'),
(93, 324, 'GN', 'Guinea', 'GUINEA', 'GIN'),
(94, 624, 'GW', 'Guinea-Bissau', 'GUINEA-BISSAU', 'GNB'),
(95, 328, 'GY', 'Guyana', 'GUYANA', 'GUY'),
(96, 332, 'HT', 'Haiti', 'HAITI', 'HTI'),
(97, 334, 'HM', 'Heard Island and Mcdonald Islands', 'HEARD ISLAND AND MCDONALD ISLANDS', 'HMD'),
(98, 336, 'VA', 'Holy See (Vatican City State)', 'HOLY SEE (VATICAN CITY STATE)', 'VAT'),
(99, 340, 'HN', 'Honduras', 'HONDURAS', 'HND'),
(100, 344, 'HK', 'Hong Kong', 'HONG KONG', 'HKG'),
(101, 348, 'HU', 'Hungary', 'HUNGARY', 'HUN'),
(102, 352, 'IS', 'Iceland', 'ICELAND', 'ISL'),
(103, 356, 'IN', 'India', 'INDIA', 'IND'),
(104, 360, 'ID', 'Indonesia', 'INDONESIA', 'IDN'),
(105, 364, 'IR', 'Iran', 'IRAN, ISLAMIC REPUBLIC OF', 'IRN'),
(106, 368, 'IQ', 'Iraq', 'IRAQ', 'IRQ'),
(107, 372, 'IE', 'Ireland', 'IRELAND', 'IRL'),
(108, 833, 'IM', 'Isle of Man', 'ISLE OF MAN', 'IMN'),
(109, 376, 'IL', 'Israel', 'ISRAEL', 'ISR'),
(110, 380, 'IT', 'Italy', 'ITALY', 'ITA'),
(111, 388, 'JM', 'Jamaica', 'JAMAICA', 'JAM'),
(112, 392, 'JP', 'Japan', 'JAPAN', 'JPN'),
(113, 832, 'JE', 'Jersey', 'JERSEY', 'JEY'),
(114, 400, 'JO', 'Jordan', 'JORDAN', 'JOR'),
(115, 398, 'KZ', 'Kazakhstan', 'KAZAKHSTAN', 'KAZ'),
(116, 404, 'KE', 'Kenya', 'KENYA', 'KEN'),
(117, 296, 'KI', 'Kiribati', 'KIRIBATI', 'KIR'),
(118, 408, 'KP', 'Korea', 'KOREA, DEMOCRATIC PEOPLE''S REPUBLIC OF', 'PRK'),
(119, 410, 'KR', 'Korea', 'KOREA, REPUBLIC OF', 'KOR'),
(120, 414, 'KW', 'Kuwait', 'KUWAIT', 'KWT'),
(121, 417, 'KG', 'Kyrgyzstan', 'KYRGYZSTAN', 'KGZ'),
(122, 418, 'LA', 'Lao People''s Democratic Republic', 'LAO PEOPLE''S DEMOCRATIC REPUBLIC', 'LAO'),
(123, 428, 'LV', 'Latvia', 'LATVIA', 'LVA'),
(124, 422, 'LB', 'Lebanon', 'LEBANON', 'LBN'),
(125, 426, 'LS', 'Lesotho', 'LESOTHO', 'LSO'),
(126, 430, 'LR', 'Liberia', 'LIBERIA', 'LBR'),
(127, 434, 'LY', 'Libyan Arab Jamahiriya', 'LIBYAN ARAB JAMAHIRIYA', 'LBY'),
(128, 438, 'LI', 'Liechtenstein', 'LIECHTENSTEIN', 'LIE'),
(129, 440, 'LT', 'Lithuania', 'LITHUANIA', 'LTU'),
(130, 442, 'LU', 'Luxembourg', 'LUXEMBOURG', 'LUX'),
(131, 446, 'MO', 'Macao', 'MACAO', 'MAC'),
(132, 807, 'MK', 'Macedonia', 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', 'MKD'),
(133, 450, 'MG', 'Madagascar', 'MADAGASCAR', 'MDG'),
(134, 454, 'MW', 'Malawi', 'MALAWI', 'MWI'),
(135, 458, 'MY', 'Malaysia', 'MALAYSIA', 'MYS'),
(136, 462, 'MV', 'Maldives', 'MALDIVES', 'MDV'),
(137, 466, 'ML', 'Mali', 'MALI', 'MLI'),
(138, 470, 'MT', 'Malta', 'MALTA', 'MLT'),
(139, 584, 'MH', 'Marshall Islands', 'MARSHALL ISLANDS', 'MHL'),
(140, 474, 'MQ', 'Martinique', 'MARTINIQUE', 'MTQ'),
(141, 478, 'MR', 'Mauritania', 'MAURITANIA', 'MRT'),
(142, 480, 'MU', 'Mauritius', 'MAURITIUS', 'MUS'),
(143, 175, 'YT', 'Mayotte', 'MAYOTTE', 'MYT'),
(144, 484, 'MX', 'Mexico', 'MEXICO', 'MEX'),
(145, 583, 'FM', 'Micronesia', 'MICRONESIA, FEDERATED STATES OF', 'FSM'),
(146, 498, 'MD', 'Moldova', 'MOLDOVA, REPUBLIC OF', 'MDA'),
(147, 492, 'MC', 'Monaco', 'MONACO', 'MCO'),
(148, 496, 'MN', 'Mongolia', 'MONGOLIA', 'MNG'),
(149, 499, 'ME', 'Montenegro', 'MONTENEGRO', 'MNE'),
(150, 500, 'MS', 'Montserrat', 'MONTSERRAT', 'MSR'),
(151, 504, 'MA', 'Morocco', 'MOROCCO', 'MAR'),
(152, 508, 'MZ', 'Mozambique', 'MOZAMBIQUE', 'MOZ'),
(153, 104, 'MM', 'Myanmar', 'MYANMAR', 'MMR'),
(154, 516, 'NA', 'Namibia', 'NAMIBIA', 'NAM'),
(155, 520, 'NR', 'Nauru', 'NAURU', 'NRU'),
(156, 524, 'NP', 'Nepal', 'NEPAL', 'NPL'),
(157, 528, 'NL', 'Netherlands', 'NETHERLANDS', 'NLD'),
(158, 540, 'NC', 'New Caledonia', 'NEW CALEDONIA', 'NCL'),
(159, 554, 'NZ', 'New Zealand', 'NEW ZEALAND', 'NZL'),
(160, 558, 'NI', 'Nicaragua', 'NICARAGUA', 'NIC'),
(161, 562, 'NE', 'Niger', 'NIGER', 'NER'),
(162, 566, 'NG', 'Nigeria', 'NIGERIA', 'NGA'),
(163, 570, 'NU', 'Niue', 'NIUE', 'NIU'),
(164, 574, 'NF', 'Norfolk Island', 'NORFOLK ISLAND', 'NFK'),
(165, 580, 'MP', 'Northern Mariana Islands', 'NORTHERN MARIANA ISLANDS', 'MNP'),
(166, 578, 'NO', 'Norway', 'NORWAY', 'NOR'),
(167, 512, 'OM', 'Oman', 'OMAN', 'OMN'),
(168, 586, 'PK', 'Pakistan', 'PAKISTAN', 'PAK'),
(169, 585, 'PW', 'Palau', 'PALAU', 'PLW'),
(170, 275, 'PS', 'Palestinian Territory, Occupied', 'PALESTINIAN TERRITORY, OCCUPIED', 'PSE'),
(171, 591, 'PA', 'Panama', 'PANAMA', 'PAN'),
(172, 598, 'PG', 'Papua New Guinea', 'PAPUA NEW GUINEA', 'PNG'),
(173, 600, 'PY', 'Paraguay', 'PARAGUAY', 'PRY'),
(174, 604, 'PE', 'Peru', 'PERU', 'PER'),
(175, 608, 'PH', 'Philippines', 'PHILIPPINES', 'PHL'),
(176, 612, 'PN', 'Pitcairn', 'PITCAIRN', 'PCN'),
(177, 616, 'PL', 'Poland', 'POLAND', 'POL'),
(178, 620, 'PT', 'Portugal', 'PORTUGAL', 'PRT'),
(179, 630, 'PR', 'Puerto Rico', 'PUERTO RICO', 'PRI'),
(180, 634, 'QA', 'Qatar', 'QATAR', 'QAT'),
(181, 638, 'RE', 'Reunion', 'REUNION', 'REU'),
(182, 642, 'RO', 'Romania', 'ROMANIA', 'ROM'),
(183, 643, 'RU', 'Russian Federation', 'RUSSIAN FEDERATION', 'RUS'),
(184, 646, 'RW', 'Rwanda', 'RWANDA', 'RWA'),
(185, 652, 'BL', 'Saint Barthelemy', 'SAINT BARTHELEMY', 'BLM'),
(186, 654, 'SH', 'Saint Helena, Ascension and Tristan da Cunha', 'SAINT HELENA, ASCENSION AND TRISTAN DA CUNHA', 'SHN'),
(187, 659, 'KN', 'Saint Kitts and Nevis', 'SAINT KITTS AND NEVIS', 'KNA'),
(188, 662, 'LC', 'Saint Lucia', 'SAINT LUCIA', 'LCA'),
(189, 663, 'MF', 'Saint Martin (French part)', 'SAINT MARTIN (FRENCH PART)', 'MAF'),
(190, 666, 'PM', 'Saint Pierre and Miquelon', 'SAINT PIERRE AND MIQUELON', 'SPM'),
(191, 670, 'VC', 'Saint Vincent and the Grenadines', 'SAINT VINCENT AND THE GRENADINES', 'VCT'),
(192, 882, 'WS', 'Samoa', 'SAMOA', 'WSM'),
(193, 674, 'SM', 'San Marino', 'SAN MARINO', 'SMR'),
(194, 678, 'ST', 'Sao Tome and Principe', 'SAO TOME AND PRINCIPE', 'STP'),
(195, 682, 'SA', 'Saudi Arabia', 'SAUDI ARABIA', 'SAU'),
(196, 686, 'SN', 'Senegal', 'SENEGAL', 'SEN'),
(197, 688, 'RS', 'Serbia', 'SERBIA', 'SRB'),
(198, 690, 'SC', 'Seychelles', 'SEYCHELLES', 'SYC'),
(199, 694, 'SL', 'Sierra Leone', 'SIERRA LEONE', 'SLE'),
(200, 702, 'SG', 'Singapore', 'SINGAPORE', 'SGP'),
(201, 534, 'SX', 'Sint Maarten (Dutch part)', 'SINT MAARTEN (DUTCH PART)', 'SXM'),
(202, 703, 'SK', 'Slovakia', 'SLOVAKIA', 'SVK'),
(203, 705, 'SI', 'Slovenia', 'SLOVENIA', 'SVN'),
(204, 90, 'SB', 'Solomon Islands', 'SOLOMON ISLANDS', 'SLB'),
(205, 706, 'SO', 'Somalia', 'SOMALIA', 'SOM'),
(206, 710, 'ZA', 'South Africa', 'SOUTH AFRICA', 'ZAF'),
(207, 239, 'GS', 'South Georgia and the South Sandwich Islands', 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', 'SGS'),
(208, 724, 'ES', 'Spain', 'SPAIN', 'ESP'),
(209, 144, 'LK', 'Sri Lanka', 'SRI LANKA', 'LKA'),
(210, 736, 'SD', 'Sudan', 'SUDAN', 'SDN'),
(211, 740, 'SR', 'Suriname', 'SURINAME', 'SUR'),
(212, 744, 'SJ', 'Svalbard and Jan Mayen', 'SVALBARD AND JAN MAYEN', 'SJM'),
(213, 748, 'SZ', 'Swaziland', 'SWAZILAND', 'SWZ'),
(214, 752, 'SE', 'Sweden', 'SWEDEN', 'SWE'),
(215, 756, 'CH', 'Switzerland', 'SWITZERLAND', 'CHE'),
(216, 760, 'SY', 'Syrian Arab Republic', 'SYRIAN ARAB REPUBLIC', 'SYR'),
(217, 158, 'TW', 'Taiwan', 'TAIWAN, PROVINCE OF CHINA', 'TWN'),
(218, 762, 'TJ', 'Tajikistan', 'TAJIKISTAN', 'TJK'),
(219, 834, 'TZ', 'Tanzania', 'TANZANIA, UNITED REPUBLIC OF', 'TZA'),
(220, 764, 'TH', 'Thailand', 'THAILAND', 'THA'),
(221, 626, 'TL', 'Timor-Leste', 'TIMOR-LESTE', 'TLS'),
(222, 768, 'TG', 'Togo', 'TOGO', 'TGO'),
(223, 772, 'TK', 'Tokelau', 'TOKELAU', 'TKL'),
(224, 776, 'TO', 'Tonga', 'TONGA', 'TON'),
(225, 780, 'TT', 'Trinidad and Tobago', 'TRINIDAD AND TOBAGO', 'TTO'),
(226, 788, 'TN', 'Tunisia', 'TUNISIA', 'TUN'),
(227, 792, 'TR', 'Turkey', 'TURKEY', 'TUR'),
(228, 795, 'TM', 'Turkmenistan', 'TURKMENISTAN', 'TKM'),
(229, 796, 'TC', 'Turks and Caicos Islands', 'TURKS AND CAICOS ISLANDS', 'TCA'),
(230, 798, 'TV', 'Tuvalu', 'TUVALU', 'TUV'),
(231, 800, 'UG', 'Uganda', 'UGANDA', 'UGA'),
(232, 804, 'UA', 'Ukraine', 'UKRAINE', 'UKR'),
(233, 784, 'AE', 'United Arab Emirates', 'UNITED ARAB EMIRATES', 'ARE'),
(234, 826, 'GB', 'United Kingdom', 'UNITED KINGDOM', 'GBR'),
(235, 840, 'US', 'United States', 'UNITED STATES', 'USA'),
(236, 581, 'UM', 'United States Minor Outlying Islands', 'UNITED STATES MINOR OUTLYING ISLANDS', 'UMI'),
(237, 858, 'UY', 'Uruguay', 'URUGUAY', 'URY'),
(238, 860, 'UZ', 'Uzbekistan', 'UZBEKISTAN', 'UZB'),
(239, 548, 'VU', 'Vanuatu', 'VANUATU', 'VUT'),
(240, 862, 'VE', 'Venezuela', 'VENEZUELA, BOLIVARIAN REPUBLIC OF', 'VEN'),
(241, 704, 'VN', 'Viet Nam', 'VIET NAM', 'VNM'),
(242, 92, 'VG', 'Virgin Islands, British', 'VIRGIN ISLANDS, BRITISH', 'VGB'),
(243, 850, 'VI', 'Virgin Islands, U.S.', 'VIRGIN ISLANDS, U.S.', 'VIR'),
(244, 876, 'WF', 'Wallis and Futuna', 'WALLIS AND FUTUNA', 'WLF'),
(245, 732, 'EH', 'Western Sahara', 'WESTERN SAHARA', 'ESH'),
(246, 887, 'YE', 'Yemen', 'YEMEN', 'YEM'),
(247, 894, 'ZM', 'Zambia', 'ZAMBIA', 'ZMB'),
(248, 716, 'ZW', 'Zimbabwe', 'ZIMBABWE', 'ZWE'),
(249, 717, 'EU', 'Europa', 'EUROPA', 'EUR');

-- Updates on version 2.0
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_referral` (
  `referral` varchar(255) NOT NULL, 
  `record_date` date NOT NULL,
  `ip` varchar(255) DEFAULT NULL,
  `session_id_person` varchar(255) NULL,
  KEY `sessionid_idx` (`session_id_person`),
  KEY `record_date_idx` (`record_date`)
) ENGINE=InnoDB CHARACTER SET `utf8`;

CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_searches` (
  `phrase` varchar(255) NOT NULL, 
  `record_date` date NOT NULL
) ENGINE=InnoDB CHARACTER SET `utf8`;

CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_eventstats` (
  `id` int NOT NULL AUTO_INCREMENT, 
  `catid` int UNSIGNED NOT NULL DEFAULT '0',
  `type` varchar(50) NOT NULL,
  `name` varchar(255) NOT NULL, 
  `description` text NULL , 
  `hasgoal` tinyint NOT NULL DEFAULT '0', 
  `goal_expectation` int NULL,
  `goal_notification` tinyint NOT NULL DEFAULT  '0',
  `goal_notification_emails` VARCHAR( 255 ) NULL,
  `checked_out` int UNSIGNED NULL,
  `checked_out_time` DATETIME NULL,
  `published` tinyint NOT NULL DEFAULT '1',
  `ordering` int NOT NULL default '0',
  `params` text NOT NULL,
  PRIMARY KEY (`id`),
  KEY `catid_idx` (`catid`),
  KEY `name_idx` (`name`)
) ENGINE=InnoDB CHARACTER SET `utf8`;

CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_eventstats_track` (
  `event_id` int NOT NULL, 
  `session_id` varchar(200) NOT NULL, 
  `eventdate` date NOT NULL, 
  `event_timestamp` int NOT NULL, 
  PRIMARY KEY (`event_id`, `session_id`, `eventdate`)
) ENGINE=InnoDB CHARACTER SET `utf8`;


CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_categories` (
  `id` int NOT NULL AUTO_INCREMENT,
  `asset_id` int unsigned NOT NULL DEFAULT '0' COMMENT 'FK to the #__assets table.',
  `parent_id` int unsigned NOT NULL DEFAULT '0',
  `lft` int NOT NULL DEFAULT '0',
  `rgt` int NOT NULL DEFAULT '0',
  `level` int unsigned NOT NULL DEFAULT '1',
  `path` varchar(255) NOT NULL DEFAULT '',
  `title` varchar(255) NOT NULL,
  `alias` varchar(255) NOT NULL,
  `description` mediumtext NOT NULL,
  `published` tinyint NOT NULL DEFAULT '1',
  `checked_out` int UNSIGNED NULL,
  `checked_out_time` datetime NULL,
  PRIMARY KEY (`id`),
  KEY `cat_idx` (`published`),
  KEY `idx_checkout` (`checked_out`),
  KEY `idx_path` (`path`),
  KEY `idx_left_right` (`lft`,`rgt`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT IGNORE INTO `#__realtimeanalytics_categories` (
	`id` ,
	`asset_id` ,
	`parent_id` ,
	`lft` ,
	`rgt` ,
	`level` ,
	`path` ,
	`title` ,
	`alias` ,
	`description` ,
	`published` ,
	`checked_out` ,
	`checked_out_time`
)
VALUES (
	'1',  '0',  '0',  '0',  '1',  '0',  'root',  'ROOT',  'ROOT', '', '1',  '0',  NULL
);

-- Updates on version 2.4
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_heatmap` (
  	`id` INT NOT NULL AUTO_INCREMENT,
  	`selector` VARCHAR(500) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  	`pageurl` VARCHAR(166) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_selector_onpage` (`selector`, `pageurl`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_heatmap_clicks` (
  	`id` INT NOT NULL AUTO_INCREMENT,
  	`record_date` DATE NOT NULL,
  	`heatmap_id` INT NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET `utf8`;

-- Updates on version 2.5
CREATE TABLE IF NOT EXISTS `#__realtimeanalytics_google` (
	`id` INT NOT NULL, 
	`token` TEXT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Exceptions queries in reverse versioning order 10.0 -> 1.0
