Send countryId attribute to check if we can populate country information.

This commit is contained in:
Roman Telezhynskyi 2023-06-29 17:57:40 +03:00
parent a459e41f1d
commit 7e9ed594ea
3 changed files with 322 additions and 17 deletions

View File

@ -26,8 +26,6 @@
**
*************************************************************************/
#include "vganalytics.h"
#include "qguiapplication.h"
#include "qstringliteral.h"
#include "vganalyticsworker.h"
#include <QDataStream>
@ -43,6 +41,7 @@
#include <QQueue>
#include <QScreen>
#include <QSettings>
#include <QStringLiteral>
#include <QTimer>
#include <QUrlQuery>
#include <QUuid>
@ -261,7 +260,6 @@ void VGAnalytics::SendEvent(const QString &eventName, const QHash<QString, QJson
//---------------------------------------------------------------------------------------------------------------------
auto VGAnalytics::InitAppStartEventParams(qint64 engagementTimeMsec) const -> QHash<QString, QJsonValue>
{
QHash<QString, QJsonValue> params{
// {QStringLiteral("category"), ""},
{QStringLiteral("qt_version"), QT_VERSION_STR},
@ -272,15 +270,312 @@ auto VGAnalytics::InitAppStartEventParams(qint64 engagementTimeMsec) const -> QH
{QStringLiteral("os_version"), QSysInfo::prettyProductName()},
{QStringLiteral("screen_size"), d->m_screenResolution},
{QStringLiteral("screen_scale_factor"), d->m_screenScaleFactor},
// In order for user activity to display in standard reports like Realtime, engagement_time_msec and session_id
// must be supplied as part of the params for an event.
// In order for user activity to display in standard reports like Realtime, engagement_time_msec and
// session_id must be supplied as part of the params for an event.
// https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=gtag#optional_parameters_for_reports
{QStringLiteral("engagement_time_msec"), engagementTimeMsec},
{QStringLiteral("gui_language"), d->m_guiLanguage},
{QStringLiteral("countryId"), TerritoryCode()},
};
return params;
}
//---------------------------------------------------------------------------------------------------------------------
auto VGAnalytics::TerritoryCode() -> QString
{
QLocale loc = QLocale::system();
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
return QLocale::territoryToCode(loc.territory());
#elif QT_VERSION >= QT_VERSION_CHECK(6, 1, 0)
return QLocale::countryToCode(loc.country());
#else
return GetTerritoryCode(loc.country());
#endif
}
//---------------------------------------------------------------------------------------------------------------------
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
auto VGAnalytics::GetTerritoryCode(QLocale::Country territory) -> QString
{
if (territory == QLocale::AnyTerritory || territory > QLocale::LastTerritory)
{
return {};
}
static const QHash<QLocale::Country, QString> territoryCodeList = {
{QLocale::Afghanistan, QLatin1String("AF")},
{QLocale::AlandIslands, QLatin1String("AX")},
{QLocale::Albania, QLatin1String("AL")},
{QLocale::Algeria, QLatin1String("DZ")},
{QLocale::AmericanSamoa, QLatin1String("AS")},
{QLocale::Andorra, QLatin1String("AD")},
{QLocale::Angola, QLatin1String("AO")},
{QLocale::Anguilla, QLatin1String("AI")},
{QLocale::Antarctica, QLatin1String("AQ")},
{QLocale::AntiguaAndBarbuda, QLatin1String("AG")},
{QLocale::Argentina, QLatin1String("AR")},
{QLocale::Armenia, QLatin1String("AM")},
{QLocale::Aruba, QLatin1String("AW")},
{QLocale::AscensionIsland, QLatin1String("AC")},
{QLocale::Australia, QLatin1String("AU")},
{QLocale::Austria, QLatin1String("AT")},
{QLocale::Azerbaijan, QLatin1String("AZ")},
{QLocale::Bahamas, QLatin1String("BS")},
{QLocale::Bahrain, QLatin1String("BH")},
{QLocale::Bangladesh, QLatin1String("BD")},
{QLocale::Barbados, QLatin1String("BB")},
{QLocale::Belarus, QLatin1String("BY")},
{QLocale::Belgium, QLatin1String("BE")},
{QLocale::Belize, QLatin1String("BZ")},
{QLocale::Benin, QLatin1String("BJ")},
{QLocale::Bermuda, QLatin1String("BM")},
{QLocale::Bhutan, QLatin1String("BT")},
{QLocale::Bolivia, QLatin1String("BO")},
{QLocale::BosniaAndHerzegovina, QLatin1String("BA")},
{QLocale::Botswana, QLatin1String("BW")},
{QLocale::BouvetIsland, QLatin1String("BV")},
{QLocale::Brazil, QLatin1String("BR")},
{QLocale::BritishIndianOceanTerritory, QLatin1String("IO")},
{QLocale::BritishVirginIslands, QLatin1String("VG")},
{QLocale::Brunei, QLatin1String("BN")},
{QLocale::Bulgaria, QLatin1String("BG")},
{QLocale::BurkinaFaso, QLatin1String("BF")},
{QLocale::Burundi, QLatin1String("BI")},
{QLocale::Cambodia, QLatin1String("KH")},
{QLocale::Cameroon, QLatin1String("CM")},
{QLocale::Canada, QLatin1String("CA")},
{QLocale::CanaryIslands, QLatin1String("IC")},
{QLocale::CapeVerde, QLatin1String("CV")},
{QLocale::CaribbeanNetherlands, QLatin1String("BQ")},
{QLocale::CaymanIslands, QLatin1String("KY")},
{QLocale::CentralAfricanRepublic, QLatin1String("CF")},
{QLocale::CeutaAndMelilla, QLatin1String("EA")},
{QLocale::Chad, QLatin1String("TD")},
{QLocale::Chile, QLatin1String("CL")},
{QLocale::China, QLatin1String("CN")},
{QLocale::ChristmasIsland, QLatin1String("CX")},
{QLocale::ClippertonIsland, QLatin1String("CP")},
{QLocale::CocosIslands, QLatin1String("CC")},
{QLocale::Colombia, QLatin1String("CO")},
{QLocale::Comoros, QLatin1String("KM")},
{QLocale::CongoBrazzaville, QLatin1String("CG")},
{QLocale::CongoKinshasa, QLatin1String("CD")},
{QLocale::CookIslands, QLatin1String("CK")},
{QLocale::CostaRica, QLatin1String("CR")},
{QLocale::Croatia, QLatin1String("HR")},
{QLocale::Cuba, QLatin1String("CU")},
{QLocale::Curacao, QLatin1String("CW")},
{QLocale::Cyprus, QLatin1String("CY")},
{QLocale::Czechia, QLatin1String("CZ")},
{QLocale::Denmark, QLatin1String("DK")},
{QLocale::DiegoGarcia, QLatin1String("DG")},
{QLocale::Djibouti, QLatin1String("DJ")},
{QLocale::Dominica, QLatin1String("DM")},
{QLocale::DominicanRepublic, QLatin1String("DO")},
{QLocale::Ecuador, QLatin1String("EC")},
{QLocale::Egypt, QLatin1String("EG")},
{QLocale::ElSalvador, QLatin1String("SV")},
{QLocale::EquatorialGuinea, QLatin1String("GQ")},
{QLocale::Eritrea, QLatin1String("ER")},
{QLocale::Estonia, QLatin1String("EE")},
{QLocale::Eswatini, QLatin1String("SZ")},
{QLocale::Ethiopia, QLatin1String("ET")},
{QLocale::Europe, QLatin1String("150")},
{QLocale::EuropeanUnion, QLatin1String("EU")},
{QLocale::FalklandIslands, QLatin1String("FK")},
{QLocale::FaroeIslands, QLatin1String("FO")},
{QLocale::Fiji, QLatin1String("FJ")},
{QLocale::Finland, QLatin1String("FI")},
{QLocale::France, QLatin1String("FR")},
{QLocale::FrenchGuiana, QLatin1String("GF")},
{QLocale::FrenchPolynesia, QLatin1String("PF")},
{QLocale::FrenchSouthernTerritories, QLatin1String("TF")},
{QLocale::Gabon, QLatin1String("GA")},
{QLocale::Gambia, QLatin1String("GM")},
{QLocale::Georgia, QLatin1String("GE")},
{QLocale::Germany, QLatin1String("DE")},
{QLocale::Ghana, QLatin1String("GH")},
{QLocale::Gibraltar, QLatin1String("GI")},
{QLocale::Greece, QLatin1String("GR")},
{QLocale::Greenland, QLatin1String("GL")},
{QLocale::Grenada, QLatin1String("GD")},
{QLocale::Guadeloupe, QLatin1String("GP")},
{QLocale::Guam, QLatin1String("GU")},
{QLocale::Guatemala, QLatin1String("GT")},
{QLocale::Guernsey, QLatin1String("GG")},
{QLocale::GuineaBissau, QLatin1String("GW")},
{QLocale::Guinea, QLatin1String("GN")},
{QLocale::Guyana, QLatin1String("GY")},
{QLocale::Haiti, QLatin1String("HT")},
{QLocale::HeardAndMcDonaldIslands, QLatin1String("HM")},
{QLocale::Honduras, QLatin1String("HN")},
{QLocale::HongKong, QLatin1String("HK")},
{QLocale::Hungary, QLatin1String("HU")},
{QLocale::Iceland, QLatin1String("IS")},
{QLocale::India, QLatin1String("IN")},
{QLocale::Indonesia, QLatin1String("ID")},
{QLocale::Iran, QLatin1String("IR")},
{QLocale::Iraq, QLatin1String("IQ")},
{QLocale::Ireland, QLatin1String("IE")},
{QLocale::IsleOfMan, QLatin1String("IM")},
{QLocale::Israel, QLatin1String("IL")},
{QLocale::Italy, QLatin1String("IT")},
{QLocale::IvoryCoast, QLatin1String("CI")},
{QLocale::Jamaica, QLatin1String("JM")},
{QLocale::Japan, QLatin1String("JP")},
{QLocale::Jersey, QLatin1String("JE")},
{QLocale::Jordan, QLatin1String("JO")},
{QLocale::Kazakhstan, QLatin1String("KZ")},
{QLocale::Kenya, QLatin1String("KE")},
{QLocale::Kiribati, QLatin1String("KI")},
{QLocale::Kosovo, QLatin1String("XK")},
{QLocale::Kuwait, QLatin1String("KW")},
{QLocale::Kyrgyzstan, QLatin1String("KG")},
{QLocale::Laos, QLatin1String("LA")},
{QLocale::LatinAmerica, QLatin1String("419")},
{QLocale::Latvia, QLatin1String("LV")},
{QLocale::Lebanon, QLatin1String("LB")},
{QLocale::Lesotho, QLatin1String("LS")},
{QLocale::Liberia, QLatin1String("LR")},
{QLocale::Libya, QLatin1String("LY")},
{QLocale::Liechtenstein, QLatin1String("LI")},
{QLocale::Lithuania, QLatin1String("LT")},
{QLocale::Luxembourg, QLatin1String("LU")},
{QLocale::Macao, QLatin1String("MO")},
{QLocale::Macedonia, QLatin1String("MK")},
{QLocale::Madagascar, QLatin1String("MG")},
{QLocale::Malawi, QLatin1String("MW")},
{QLocale::Malaysia, QLatin1String("MY")},
{QLocale::Maldives, QLatin1String("MV")},
{QLocale::Mali, QLatin1String("ML")},
{QLocale::Malta, QLatin1String("MT")},
{QLocale::MarshallIslands, QLatin1String("MH")},
{QLocale::Martinique, QLatin1String("MQ")},
{QLocale::Mauritania, QLatin1String("MR")},
{QLocale::Mauritius, QLatin1String("MU")},
{QLocale::Mayotte, QLatin1String("YT")},
{QLocale::Mexico, QLatin1String("MX")},
{QLocale::Micronesia, QLatin1String("FM")},
{QLocale::Moldova, QLatin1String("MD")},
{QLocale::Monaco, QLatin1String("MC")},
{QLocale::Mongolia, QLatin1String("MN")},
{QLocale::Montenegro, QLatin1String("ME")},
{QLocale::Montserrat, QLatin1String("MS")},
{QLocale::Morocco, QLatin1String("MA")},
{QLocale::Mozambique, QLatin1String("MZ")},
{QLocale::Myanmar, QLatin1String("MM")},
{QLocale::Namibia, QLatin1String("NA")},
{QLocale::NauruCountry, QLatin1String("NR")},
{QLocale::Nepal, QLatin1String("NP")},
{QLocale::Netherlands, QLatin1String("NL")},
{QLocale::NewCaledonia, QLatin1String("NC")},
{QLocale::NewZealand, QLatin1String("NZ")},
{QLocale::Nicaragua, QLatin1String("NI")},
{QLocale::Nigeria, QLatin1String("NG")},
{QLocale::Niger, QLatin1String("NE")},
{QLocale::Niue, QLatin1String("NU")},
{QLocale::NorfolkIsland, QLatin1String("NF")},
{QLocale::NorthernMarianaIslands, QLatin1String("MP")},
{QLocale::NorthKorea, QLatin1String("KP")},
{QLocale::Norway, QLatin1String("NO")},
{QLocale::Oman, QLatin1String("OM")},
{QLocale::OutlyingOceania, QLatin1String("QO")},
{QLocale::Pakistan, QLatin1String("PK")},
{QLocale::Palau, QLatin1String("PW")},
{QLocale::PalestinianTerritories, QLatin1String("PS")},
{QLocale::Panama, QLatin1String("PA")},
{QLocale::PapuaNewGuinea, QLatin1String("PG")},
{QLocale::Paraguay, QLatin1String("PY")},
{QLocale::Peru, QLatin1String("PE")},
{QLocale::Philippines, QLatin1String("PH")},
{QLocale::Pitcairn, QLatin1String("PN")},
{QLocale::Poland, QLatin1String("PL")},
{QLocale::Portugal, QLatin1String("PT")},
{QLocale::PuertoRico, QLatin1String("PR")},
{QLocale::Qatar, QLatin1String("QA")},
{QLocale::Reunion, QLatin1String("RE")},
{QLocale::Romania, QLatin1String("RO")},
{QLocale::Russia, QLatin1String("RU")},
{QLocale::Rwanda, QLatin1String("RW")},
{QLocale::SaintBarthelemy, QLatin1String("BL")},
{QLocale::SaintHelena, QLatin1String("SH")},
{QLocale::SaintKittsAndNevis, QLatin1String("KN")},
{QLocale::SaintLucia, QLatin1String("LC")},
{QLocale::SaintMartin, QLatin1String("MF")},
{QLocale::SaintPierreAndMiquelon, QLatin1String("PM")},
{QLocale::SaintVincentAndGrenadines, QLatin1String("VC")},
{QLocale::Samoa, QLatin1String("WS")},
{QLocale::SanMarino, QLatin1String("SM")},
{QLocale::SaoTomeAndPrincipe, QLatin1String("ST")},
{QLocale::SaudiArabia, QLatin1String("SA")},
{QLocale::Senegal, QLatin1String("SN")},
{QLocale::Serbia, QLatin1String("RS")},
{QLocale::Seychelles, QLatin1String("SC")},
{QLocale::SierraLeone, QLatin1String("SL")},
{QLocale::Singapore, QLatin1String("SG")},
{QLocale::SintMaarten, QLatin1String("SX")},
{QLocale::Slovakia, QLatin1String("SK")},
{QLocale::Slovenia, QLatin1String("SI")},
{QLocale::SolomonIslands, QLatin1String("SB")},
{QLocale::Somalia, QLatin1String("SO")},
{QLocale::SouthAfrica, QLatin1String("ZA")},
{QLocale::SouthGeorgiaAndSouthSandwichIslands, QLatin1String("GS")},
{QLocale::SouthKorea, QLatin1String("KR")},
{QLocale::SouthSudan, QLatin1String("SS")},
{QLocale::Spain, QLatin1String("ES")},
{QLocale::SriLanka, QLatin1String("LK")},
{QLocale::Sudan, QLatin1String("SD")},
{QLocale::Suriname, QLatin1String("SR")},
{QLocale::SvalbardAndJanMayen, QLatin1String("SJ")},
{QLocale::Sweden, QLatin1String("SE")},
{QLocale::Switzerland, QLatin1String("CH")},
{QLocale::Syria, QLatin1String("SY")},
{QLocale::Taiwan, QLatin1String("TW")},
{QLocale::Tajikistan, QLatin1String("TJ")},
{QLocale::Tanzania, QLatin1String("TZ")},
{QLocale::Thailand, QLatin1String("TH")},
{QLocale::TimorLeste, QLatin1String("TL")},
{QLocale::Togo, QLatin1String("TG")},
{QLocale::TokelauCountry, QLatin1String("TK")},
{QLocale::Tonga, QLatin1String("TO")},
{QLocale::TrinidadAndTobago, QLatin1String("TT")},
{QLocale::TristanDaCunha, QLatin1String("TA")},
{QLocale::Tunisia, QLatin1String("TN")},
{QLocale::Turkey, QLatin1String("TR")},
{QLocale::Turkmenistan, QLatin1String("TM")},
{QLocale::TurksAndCaicosIslands, QLatin1String("TC")},
{QLocale::TuvaluCountry, QLatin1String("TV")},
{QLocale::Uganda, QLatin1String("UG")},
{QLocale::Ukraine, QLatin1String("UA")},
{QLocale::UnitedArabEmirates, QLatin1String("AE")},
{QLocale::UnitedKingdom, QLatin1String("GB")},
{QLocale::UnitedStatesOutlyingIslands, QLatin1String("UM")},
{QLocale::UnitedStates, QLatin1String("US")},
{QLocale::UnitedStatesVirginIslands, QLatin1String("VI")},
{QLocale::Uruguay, QLatin1String("UY")},
{QLocale::Uzbekistan, QLatin1String("UZ")},
{QLocale::Vanuatu, QLatin1String("VU")},
{QLocale::VaticanCity, QLatin1String("VA")},
{QLocale::Venezuela, QLatin1String("VE")},
{QLocale::Vietnam, QLatin1String("VN")},
{QLocale::WallisAndFutuna, QLatin1String("WF")},
{QLocale::WesternSahara, QLatin1String("EH")},
{QLocale::World, QLatin1String("001")},
{QLocale::Yemen, QLatin1String("YE")},
{QLocale::Zambia, QLatin1String("ZM")},
{QLocale::Zimbabwe, QLatin1String("ZW")},
};
if (territoryCodeList.contains(territory))
{
return territoryCodeList.value(territory);
}
return QString();
}
#endif
//---------------------------------------------------------------------------------------------------------------------
/**
* Qut stream to persist class GAnalytics.

View File

@ -30,6 +30,10 @@
#include <QObject>
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
#include <QLocale>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
#include "../vmisc/defglobal.h"
#endif
@ -96,6 +100,11 @@ private:
auto InitAppStartEventParams(qint64 engagementTimeMsec) const -> QHash<QString, QJsonValue>;
static auto TerritoryCode() -> QString;
#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0)
static auto GetTerritoryCode(QLocale::Country territory) -> QString;
#endif
friend auto operator<<(QDataStream &outStream, const VGAnalytics &analytics) -> QDataStream &;
friend auto operator>>(QDataStream &inStream, VGAnalytics &analytics) -> QDataStream &;
};

View File

@ -35,6 +35,7 @@
#include <QNetworkRequest>
#include <QObject>
#include <QQueue>
#include <QStringLiteral>
#include <QTimer>
#include <QUrlQuery>
#include <QtGlobal>
@ -66,19 +67,19 @@ public:
QNetworkRequest m_request{}; // NOLINT(misc-non-private-member-variables-in-classes)
enum VGAnalytics::LogLevel m_logLevel{VGAnalytics::Debug}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_measurementId{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_apiSecret{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_clientID{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_userID{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_appName{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_appVersion{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_guiLanguage{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_screenResolution{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_repoRevision{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_measurementId{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_apiSecret{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_clientID{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_userID{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_appName{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_appVersion{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_guiLanguage{}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_screenResolution{QStringLiteral("0x0")}; // NOLINT(misc-non-private-member-variables-in-classes)
QString m_repoRevision{QStringLiteral("Unknown")}; // NOLINT(misc-non-private-member-variables-in-classes)
bool m_isEnabled{false}; // NOLINT(misc-non-private-member-variables-in-classes)
int m_timerInterval{30000}; // NOLINT(misc-non-private-member-variables-in-classes)
qreal m_screenScaleFactor{}; // NOLINT(misc-non-private-member-variables-in-classes)
bool m_isEnabled{false}; // NOLINT(misc-non-private-member-variables-in-classes)
int m_timerInterval{30000}; // NOLINT(misc-non-private-member-variables-in-classes)
qreal m_screenScaleFactor{0}; // NOLINT(misc-non-private-member-variables-in-classes)
const static QLatin1String dateTimeFormat;