diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/plugin/abstractquerybuilder.cpp.autosave | 15 | ||||
-rw-r--r-- | src/plugin/analytics.cpp | 250 | ||||
-rw-r--r-- | src/plugin/analytics.h | 116 | ||||
-rw-r--r-- | src/plugin/configutil.cpp | 133 | ||||
-rw-r--r-- | src/plugin/configutil.h | 55 | ||||
-rw-r--r-- | src/plugin/context.cpp | 151 | ||||
-rw-r--r-- | src/plugin/context.h | 74 | ||||
-rw-r--r-- | src/plugin/googlebuilder.cpp | 104 | ||||
-rw-r--r-- | src/plugin/googlebuilder.h | 72 | ||||
-rw-r--r-- | src/plugin/hitbuilder.cpp | 141 | ||||
-rw-r--r-- | src/plugin/hitbuilder.h | 71 | ||||
-rw-r--r-- | src/plugin/matomobuilder.cpp | 96 | ||||
-rw-r--r-- | src/plugin/matomobuilder.h | 68 | ||||
-rw-r--r-- | src/plugin/plugin.cpp | 63 | ||||
-rw-r--r-- | src/plugin/plugin.h | 51 | ||||
-rw-r--r-- | src/plugin/plugin.pri | 20 | ||||
-rw-r--r-- | src/plugin/plugin.pro | 42 | ||||
-rw-r--r-- | src/plugin/qmldir | 2 | ||||
-rw-r--r-- | src/src.pro | 9 |
19 files changed, 1533 insertions, 0 deletions
diff --git a/src/plugin/abstractquerybuilder.cpp.autosave b/src/plugin/abstractquerybuilder.cpp.autosave new file mode 100644 index 0000000..5cf8e21 --- /dev/null +++ b/src/plugin/abstractquerybuilder.cpp.autosave @@ -0,0 +1,15 @@ +#include "abstractquerybuilder.h" + +HitBuilder::HitBuilder() +{ + +} + +HitBuilder::~HitBuilder() +{ +} + +void HitBuilder::addQueryItem(const QString &key, const QString &value) +{ + m_query.addQueryItem(key, value); +} diff --git a/src/plugin/analytics.cpp b/src/plugin/analytics.cpp new file mode 100644 index 0000000..229258c --- /dev/null +++ b/src/plugin/analytics.cpp @@ -0,0 +1,250 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "analytics.h" +#include "hitbuilder.h" +#include "matomobuilder.h" +#include "googlebuilder.h" +#include "configutil.h" +#include "context.h" + +/*! + * \qmlmodule Analytics + */ + +/*! + * \qmltype Analytics + * \inqmlmodule Analytics + * \brief Provides tracking operations for visits and events. + + * To use this API you need to have an analytics.json configuration file located + * either as resource file or in your home folder. The configuration file needs to provide the + * server url, tracker id, client id as a minimum. + + * The API will send request to the Matomo server to track certain user interface statistics. You need to + * place tracking code inside your user interface to track this behavior. + */ + +/*! + * \class AnalyticsAttached + * \inmodule QtAnalytics + * \brief The attached object to the Analytics. + */ + +/*! + * \class Analytics + * \inmodule QtAnalytics + * \brief Proxy class to access the selected tracker platform. + */ + +/*! + * \brief Construct a new attached object. + * \param parent Parent object + */ +AnalyticsAttached::AnalyticsAttached(QObject *parent) + : QObject(parent) +{ +} + +AnalyticsAttached::~AnalyticsAttached() +{ +} + +/*! + * \qmlmethod void Analytics::sendPing() + * Sends a heartbeat request to the tracking server + * + * A ping will only update the visit's total time. + * It is used to provide accurate "visit duration" metrics. + */ +void AnalyticsAttached::sendPing() +{ + Analytics::instance(this)->sendPing(); +} + +/*! + * \qmlmethod void Analytics::sendVisit(path, action, dimensions) + * + * Sends a visit request to the tracking server + * + * The visit location will be identified by the \a path. The optional \a action identifies what is happening. The optional \a dimensions allows you + * to send further information as defined by the servers custom dimensions. Additional to this information also the + * custom variables defined will be send to the server. + * + */ +void AnalyticsAttached::sendVisit(const QString &path, const QString &action) +{ + Analytics::instance(this)->sendVisit(path, action); +} + +/*! + * \qmlmethod void Analytics::sendEvent(path, category, action, name, int value, dimensions) + * + * Sends an event request to the tracking server. The path provides the location inside the user interface. + * The action what is happening. The event category where somethign is heppening (e.g. videos, music. games). The + * name the event name to track. A value can be an additional information to track. Additional you can provide + * a set of key/value pairs as defined on the Matamo server. + */ +void AnalyticsAttached::sendEvent(const QString &category, const QString &action, + const QString &name, const QString &value) +{ + Analytics::instance(this)->sendEvent(category, action, name, value); +} + +void AnalyticsAttached::setVariables(QVariantMap customVariables) +{ + if (m_variables == customVariables) { + return; + } + m_variables = customVariables; + emit variablesChanged(); +} + + +// Analytics + +Analytics* Analytics::s_instance = nullptr; + +Analytics::Analytics(QObject *parent) + : QObject(parent) + , m_context(new Context(this)) + , m_builder(nullptr) +{ + const QJsonObject& data = ConfigUtil::loadJSON("analytics"); + const QVariantMap& o = ConfigUtil::toVariantMap(data); + m_context->setConfig(o); +} + +Analytics::~Analytics() +{ +} + +Analytics *Analytics::instance(QObject *attached) +{ + qDebug() << Q_FUNC_INFO; + if (!Analytics::s_instance) { + Analytics::s_instance = new Analytics(QCoreApplication::instance()); + } + if (attached && !Analytics::s_instance->context()->hasNetwork()) { + Analytics::s_instance->context()->discoverNetwork(attached->parent()); + } + return Analytics::s_instance; +} + +AnalyticsAttached *Analytics::qmlAttachedProperties(QObject* object) +{ + return new AnalyticsAttached(object); +} + +void Analytics::sendPing() +{ + qDebug() << Q_FUNC_INFO; +} + + +void Analytics::sendVisit(const QString &path, const QString &action) +{ + qDebug() << Q_FUNC_INFO << path << action; + HitBuilder* builder = getBuilder(); + if (builder) { + builder->initQuery(); + builder->trackPage(path, action); + builder->sendQuery(); + builder->reset(); + } +} + + +void Analytics::sendEvent( const QString &category, + const QString &action, const QString &name, + const QString &value) { + + qDebug() << Q_FUNC_INFO << category << action; + HitBuilder* builder = getBuilder(); + if (builder) { + builder->initQuery(); + builder->trackEvent(category, action, name, value); + builder->sendQuery(); + builder->reset(); + } +} + + +HitBuilder* Analytics::getBuilder() +{ + if (!m_builder) { + QString tracker = context()->configString("tracker"); + qDebug() << "found tracker " << tracker; + if (tracker == "matomo") { + m_builder = new MatomoBuilder(context(), this); + } else if (tracker == "google") { + m_builder = new GoogleBuilder(context(), this); + } else { + qWarning() << "not supported builder" << tracker; + } + } + return m_builder; +} + +void Analytics::onReplyFinished(QNetworkReply *reply) +{ + emit replyFinished(reply); + qDebug() << "network reply finished: " << reply->url(); + reply->deleteLater(); +} + +Context *Analytics::context() const +{ + return m_context; +} + +//QString Analytics::userAgent() const +//{ +// const QString& name = settings()->value("applicationName").toString(); +// const QString& version = settings()->value("applicationVersion").toString(); +// const QString& lang = userLanguage(); +// const QString& os = settings()->value("os").toString(); +// return QString("%1/%2 (%3;%4) Analytics/1.0 (Qt/%5)").arg(name).arg(version).arg(os).arg(lang).arg(QT_VERSION_STR); +//} + +//QString Analytics::userLanguage() const +//{ +// return QLocale::system().name().toLower().replace("_", "-"); +//} + diff --git a/src/plugin/analytics.h b/src/plugin/analytics.h new file mode 100644 index 0000000..56d17c8 --- /dev/null +++ b/src/plugin/analytics.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> +#include <QtQml> +#include <QtNetwork> + +class Context; +class HitBuilder; +class Analytics; + +class AnalyticsAttached : public QObject +{ + Q_OBJECT + + /** + * In QML it shall look like + * Analytics.customVariables: { + * "myVariable1": "myValue1", + * "myVariable2": "myValue2" + * } + */ + Q_PROPERTY(QVariantMap variables READ variables WRITE setVariables NOTIFY variablesChanged) +public: + AnalyticsAttached(QObject *parent = nullptr); + virtual ~AnalyticsAttached(); + + Q_INVOKABLE void sendPing(); + Q_INVOKABLE void sendVisit(const QString &path, const QString &name); + Q_INVOKABLE void sendEvent(const QString &category, const QString &action, const QString &name, const QString &value); + + QVariantMap variables() const { return m_variables; } + +public slots: + void setVariables(QVariantMap variables); + +signals: + void variablesChanged(); + +private: + QVariantMap m_variables; +}; + + +class Analytics : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY(Analytics) +public: + explicit Analytics(QObject *parent = nullptr); + virtual ~Analytics(); + + static Analytics *instance(QObject *attached); + static AnalyticsAttached* qmlAttachedProperties(QObject* ); + HitBuilder *getBuilder(); + void sendPing(); + void sendVisit(const QString &path, const QString &name); + void sendEvent(const QString &category, const QString &action, + const QString &name, const QString &value); + Context *context() const; + +private: + // QString userAgent() const; + // QString userLanguage() const; + void dispatch(HitBuilder *builder); + void processQueue(); + void onReplyFinished(QNetworkReply* reply); +signals: + void sendHitRequest(const QUrl& url); + void replyFinished(QNetworkReply* reply); +private: + static Analytics *s_instance; + Context *m_context; + HitBuilder *m_builder; +}; + + + +QML_DECLARE_TYPEINFO(Analytics, QML_HAS_ATTACHED_PROPERTIES) diff --git a/src/plugin/configutil.cpp b/src/plugin/configutil.cpp new file mode 100644 index 0000000..a547c30 --- /dev/null +++ b/src/plugin/configutil.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "configutil.h" + +/*! + * \class ConfigUtil + * \inmodule QtAnalytics + * \brief A configuration utility. + */ + +ConfigUtil::ConfigUtil() +{ + +} + + +QString ConfigUtil::resolvePath(const QString &name) +{ + QString upper = name.toUpper(); + QString lower = name.toLower(); + QString path = qEnvironmentVariable(name.toUpper().toLatin1() + "_CONFIG", QString(":/%1.json").arg(name.toLower().data())); + if (!QFile(path).exists()) { + qWarning() << "No analytics configuration"; + return QString(); + } + return path; +} + +QByteArray ConfigUtil::readJSON(const QString &path) +{ + if (path.isEmpty()) { + qWarning() << "invalid config path"; + return QByteArray(); + } + QFile device(path); + if (!device.open(QIODevice::ReadOnly)) { + qWarning() << "Can not open analytics config"; + return QByteArray(); + } + return device.readAll(); +} + +QJsonObject ConfigUtil::parseJSON(const QByteArray &data) +{ + if (data.isNull()) { + qWarning() << "invalid config data"; + return QJsonObject(); + } + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(data, &error); + if (error.error != QJsonParseError::NoError) { + qWarning() << "Error parsing analytics settings"; + qWarning() << error.errorString(); + return QJsonObject(); + } + if (!doc.isObject()) { + qWarning() << "settings must be a valid JSON object"; + return QJsonObject(); + } + return doc.object(); +} + +QJsonObject ConfigUtil::loadJSON(const QString &name) +{ + QString path = resolvePath(name); + if (path.isEmpty()) { + return QJsonObject(); + } + QByteArray data = readJSON(path); + return parseJSON(data); +} + +QJsonObject ConfigUtil::mergeJSON(const QJsonObject &a, const QJsonObject &b) +{ + QJsonObject result(a); + for (auto key : b.keys()) { + result.insert(key, b.value(key)); + } + return result; +} + +QVariantMap ConfigUtil::toVariantMap(const QJsonObject &o) +{ + return o.toVariantMap(); +} + +QVariantMap ConfigUtil::mergeMap(const QVariantMap &a, const QVariantMap &b) +{ + QVariantMap result(a); + QMapIterator<QString, QVariant> i(b); + while (i.hasNext()) { + i.next(); + result.insert(i.key(), i.value()); + } + return result; +} + diff --git a/src/plugin/configutil.h b/src/plugin/configutil.h new file mode 100644 index 0000000..9294f89 --- /dev/null +++ b/src/plugin/configutil.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> + +class ConfigUtil +{ +private: + ConfigUtil(); +public: + static QString resolvePath(const QString &name); + static QByteArray readJSON(const QString &path); + static QJsonObject parseJSON(const QByteArray &data); + static QJsonObject loadJSON(const QString &name); + static QJsonObject mergeJSON(const QJsonObject &a, const QJsonObject &b); + static QVariantMap toVariantMap(const QJsonObject &o); + static QVariantMap mergeMap(const QVariantMap &a, const QVariantMap &b); +}; diff --git a/src/plugin/context.cpp b/src/plugin/context.cpp new file mode 100644 index 0000000..c38f558 --- /dev/null +++ b/src/plugin/context.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "context.h" +#include "configutil.h" + + +/*! + * \class IContext + * \inmodule QtAnalytics + * \brief An interface to allow independent testing for builders. + */ + +/*! + * \class Context + * \inmodule QtAnalytics + * \brief A set of operations exposed to builders. + */ + +IContext::~IContext() +{ + +} + + +Context::Context(QObject *parent) + : QObject (parent) + , m_network(nullptr) +{ +} + +Context::~Context() +{ +} + +QVariantMap Context::config() const +{ + return m_config; +} + +// network provides access to the network manager +// to send requests. +QNetworkAccessManager *Context::network() const +{ + qDebug() << Q_FUNC_INFO; + return m_network; +} + +bool Context::hasNetwork() const +{ + return m_network != nullptr; +} + +QVariant Context::configValue(const QString &key, const QVariant &defaultValue) const +{ + return m_config.value(key, defaultValue); +} + +QString Context::configString(const QString &key, const QString &defaultValue) const +{ + return configValue(key, defaultValue).toString(); +} + +QNetworkReply *Context::httpGet(const QNetworkRequest &request) const +{ + qDebug() << Q_FUNC_INFO << request.url(); + return network()->get(request); +} + +QNetworkReply *Context::httpPost(const QNetworkRequest &request, const QByteArray &data) const +{ + qDebug() << Q_FUNC_INFO << request.url() << data; + return network()->post(request, data); +} + +void Context::discoverNetwork(QObject *object) +{ + qDebug() << Q_FUNC_INFO; + if (m_network) { + return; + } + if (object) { + // try network via qmlengine + QQmlEngine *engine = qmlEngine(object); + if (engine) { + m_network = engine->networkAccessManager(); + connect(m_network, &QNetworkAccessManager::finished, this, &Context::onReplyFinished); + } + } + // create a custome network manager + if (!m_network) { + m_network = new QNetworkAccessManager(this); + connect(m_network, &QNetworkAccessManager::finished, this, &Context::onReplyFinished); + } +} + +void Context::onReplyFinished(QNetworkReply *reply) +{ + qDebug() << "reply finished: " << reply->url().toString(); +} + +void Context::setConfig(const QVariantMap &config) +{ + m_config = config; +} + +void Context::updateConfig(const QVariantMap &o) +{ + setConfig(ConfigUtil::mergeMap(m_config, o)); +} + +void Context::setNetwork(QNetworkAccessManager *network) +{ + m_network = network; +} + diff --git a/src/plugin/context.h b/src/plugin/context.h new file mode 100644 index 0000000..6326a03 --- /dev/null +++ b/src/plugin/context.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> +#include <QtNetwork> +#include <QtQml> + +class IContext { +public: + virtual ~IContext(); + virtual QVariant configValue(const QString &key, const QVariant &defaultValue) const = 0; + virtual QNetworkReply* httpGet(const QNetworkRequest& request) const = 0; + virtual QNetworkReply* httpPost(const QNetworkRequest& request, const QByteArray &data) const = 0; +}; + +class Context : public QObject, public IContext +{ + Q_OBJECT +public: + Context(QObject *parent=nullptr); + ~Context(); + void setConfig(const QVariantMap &config); + void updateConfig(const QVariantMap &o); + QVariantMap config() const; + void setNetwork(QNetworkAccessManager *network); + QNetworkAccessManager *network() const; + bool hasNetwork() const; + QVariant configValue(const QString &key, const QVariant &defaultValue=QVariant()) const; + QString configString(const QString &key, const QString &defaultValue=QString()) const; + QNetworkReply* httpGet(const QNetworkRequest& request) const; + QNetworkReply* httpPost(const QNetworkRequest& request, const QByteArray &data) const; + void discoverNetwork(QObject *object); + void onReplyFinished(QNetworkReply *reply); +private: + QVariantMap m_config; + QNetworkAccessManager *m_network; +}; diff --git a/src/plugin/googlebuilder.cpp b/src/plugin/googlebuilder.cpp new file mode 100644 index 0000000..394ea3a --- /dev/null +++ b/src/plugin/googlebuilder.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "googlebuilder.h" + +#include "context.h" + + +/*! + * \class GoogleBuilder + * \inmodule QtAnalytics + * \brief Plugin for the google tracking platform. + */ + +// See https://developers.google.com/analytics/devguides/collection/protocol/v1/ + +const QString GoogleBuilder::TRACKER_ID("tid"); +const QString GoogleBuilder::VERSION("v"); +const QString GoogleBuilder::DATA_SOURCE("ds"); +const QString GoogleBuilder::DOCUMENT_PATH("dp"); +const QString GoogleBuilder::DOCUMENT_TITLE("dt"); +const QString GoogleBuilder::EVENT_CATEGORY("ec"); +const QString GoogleBuilder::EVENT_ACTION("ea"); +const QString GoogleBuilder::EVENT_LABEL("el"); +const QString GoogleBuilder::EVENT_VALUE("ev"); +const QString GoogleBuilder::HIT_TYPE("t"); +const QString GoogleBuilder::CLIENT_ID("cid"); + +GoogleBuilder::GoogleBuilder(Context *context, QObject *parent) + : HitBuilder(context, parent) +{ +} + +GoogleBuilder::~GoogleBuilder() +{ +} + +void GoogleBuilder::initQuery() +{ + const QString& server = configString("server", "https://www.google-analytics.com/collect"); + m_url = QUrl(server); + addQueryItem(VERSION, "1"); + configQueryItem(TRACKER_ID); + configQueryItem(CLIENT_ID); +} + +void GoogleBuilder::trackPage(const QString &path, const QString &title) +{ + addQueryItem(HIT_TYPE, "pageview"); + addQueryItem(DOCUMENT_PATH, path); + addQueryItem(DOCUMENT_TITLE, title); +} + +void GoogleBuilder::trackEvent(const QString &category, const QString &action, const QString &label, const QString &value) +{ + addQueryItem(EVENT_CATEGORY, category); + addQueryItem(EVENT_ACTION, action); + if (!label.isNull()) { + addQueryItem(EVENT_LABEL, label); + } + if (!value.isNull()) { + addQueryItem(EVENT_VALUE, value); + } +} + +QNetworkReply *GoogleBuilder::sendQuery() +{ + return HitBuilder::sendQuery(); +} diff --git a/src/plugin/googlebuilder.h b/src/plugin/googlebuilder.h new file mode 100644 index 0000000..c974431 --- /dev/null +++ b/src/plugin/googlebuilder.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> + +#include "hitbuilder.h" + +class Context; + +class GoogleBuilder : public HitBuilder +{ + Q_OBJECT +public: + static const QString TRACKER_ID; + static const QString VERSION; + static const QString DATA_SOURCE; + static const QString DOCUMENT_PATH; + static const QString DOCUMENT_TITLE; + static const QString EVENT_CATEGORY; + static const QString EVENT_ACTION; + static const QString EVENT_LABEL; + static const QString EVENT_VALUE; + static const QString HIT_TYPE; + static const QString CLIENT_ID; + + explicit GoogleBuilder(Context *context, QObject *parent=nullptr); + ~GoogleBuilder(); + + // HitBuilder interface +public: + void initQuery(); + void trackPage(const QString &path, const QString &title); + void trackEvent(const QString &category, const QString &action, const QString &label, const QString &value); + QNetworkReply *sendQuery(); +}; diff --git a/src/plugin/hitbuilder.cpp b/src/plugin/hitbuilder.cpp new file mode 100644 index 0000000..3453b25 --- /dev/null +++ b/src/plugin/hitbuilder.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "hitbuilder.h" +#include "context.h" + +/*! + * \class HitBuilder + * \inmodule QtAnalytics + * \brief An abstract interface for tracking platforms. + */ + +HitBuilder::HitBuilder(Context *context, QObject *parent) + : QObject(parent) + , m_context(context) +{ +} + +HitBuilder::~HitBuilder() +{ +} + +void HitBuilder::initQuery() +{ + m_url = QUrl(configString("server")); +} + +void HitBuilder::trackPage(const QString &/*path*/, const QString &/*title*/) +{ +} + +void HitBuilder::trackEvent(const QString &/*category*/, const QString &/*action*/, const QString &/*label*/, const QString &/*value*/) +{ +} + +QNetworkReply *HitBuilder::sendQuery() +{ + QUrl url(http://code.qt.io/m_url); + qDebug() << "url to request: " << url; + url.setQuery(query()); + qDebug() << "url to request: " << url; + QNetworkRequest request(url); + // by default use http get requests + return httpGet(request); +} + +void HitBuilder::reset() +{ + m_query.clear(); + m_url.clear(); +} + + +void HitBuilder::addQueryItem(const QString &key, const QString &value) +{ + if (value.isEmpty()) { + return; + } + m_query.addQueryItem(key, value); +} + +void HitBuilder::configQueryItem(const QString &key, const QString &defaultValue) +{ + QString value = configString(key, defaultValue); + if (value.isEmpty()) { + return; + } + m_query.addQueryItem(key, value); +} + +QVariant HitBuilder::configValue(const QString &key, const QVariant &defaultValue) const +{ + return context()->configValue(key, defaultValue); +} + +QString HitBuilder::configString(const QString &key, const QString &defaultValue) const +{ + return context()->configString(key, defaultValue); +} + +QNetworkReply *HitBuilder::httpGet(const QNetworkRequest &request) +{ + return context()->httpGet(request); +} + +QNetworkReply *HitBuilder::httpPost(const QNetworkRequest &request, const QByteArray &data) +{ + return context()->httpPost(request, data); +} + +Context *HitBuilder::context() const +{ + return m_context; +} + +QUrlQuery HitBuilder::query() const +{ + return m_query; +} + +QUrl HitBuilder::url() const +{ + return m_url; +} + diff --git a/src/plugin/hitbuilder.h b/src/plugin/hitbuilder.h new file mode 100644 index 0000000..1c64571 --- /dev/null +++ b/src/plugin/hitbuilder.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> +#include <QtNetwork> + +class Context; + +class HitBuilder : public QObject +{ + Q_OBJECT +public: + explicit HitBuilder(Context *context, QObject *parent=nullptr); + virtual ~HitBuilder(); + virtual void initQuery(); + virtual void trackPage(const QString &path, const QString &title); + virtual void trackEvent(const QString &category, const QString &action, const QString &label, const QString &value); + virtual QNetworkReply *sendQuery(); + virtual void reset(); + void addQueryItem(const QString &key, const QString& value); + void configQueryItem(const QString &key, const QString &defaultValue=QString()); + QVariant configValue(const QString& key, const QVariant &defaultValue=QVariant()) const; + QString configString(const QString &key, const QString &defaultValue=QString()) const; + QNetworkReply *httpGet(const QNetworkRequest& request); + QNetworkReply *httpPost(const QNetworkRequest& request, const QByteArray &data); + Context *context() const; + QUrlQuery query() const; + QUrl url() const; + +protected: + Context *m_context; + QUrlQuery m_query; + QUrl m_url; + }; diff --git a/src/plugin/matomobuilder.cpp b/src/plugin/matomobuilder.cpp new file mode 100644 index 0000000..c1e0206 --- /dev/null +++ b/src/plugin/matomobuilder.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "matomobuilder.h" + +#include "context.h" + +/*! + * \class MatomoBuilder + * \inmodule QtAnalytics + * \brief Plugin for the matomo tracking platform. + */ + +// See https://developer.matomo.org/api-reference/tracking-api +const QString MatomoBuilder::SITE_ID("idsite"); +const QString MatomoBuilder::ACTION_NAME("action_name"); +const QString MatomoBuilder::ACTION_URL("url"); +const QString MatomoBuilder::API_VERSION("apiv"); +const QString MatomoBuilder::EVENT_CATEGORY("e_c"); +const QString MatomoBuilder::EVENT_ACTION("e_a"); +const QString MatomoBuilder::EVENT_NAME("e_n"); +const QString MatomoBuilder::EVENT_VALUE("e_v"); +const QString MatomoBuilder::RECORDING("rec"); + + +MatomoBuilder::MatomoBuilder(Context *context, QObject *parent) + : HitBuilder(context, parent) +{ +} + +MatomoBuilder::~MatomoBuilder() +{ +} + +void MatomoBuilder::initQuery() +{ + HitBuilder::initQuery(); + addQueryItem(API_VERSION, "1"); + configQueryItem(SITE_ID); + addQueryItem(RECORDING, "1"); +} + +void MatomoBuilder::trackPage(const QString &path, const QString &title) +{ + QString domain = configString("domain"); + QString url = QString("%1/%2").arg(domain).arg(path); + addQueryItem(ACTION_URL, url); + addQueryItem(ACTION_NAME, title); +} + +void MatomoBuilder::trackEvent(const QString &category, const QString &action, const QString &label, const QString &value) +{ + addQueryItem(EVENT_CATEGORY, category); + addQueryItem(EVENT_ACTION, action); + if (!label.isNull()) { + addQueryItem(EVENT_NAME, label); + } + if (!value.isNull()) { + addQueryItem(EVENT_VALUE, value); + } +} diff --git a/src/plugin/matomobuilder.h b/src/plugin/matomobuilder.h new file mode 100644 index 0000000..14034ad --- /dev/null +++ b/src/plugin/matomobuilder.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#pragma once + +#include <QtCore> + +#include "hitbuilder.h" + +class Context; + + +class MatomoBuilder : public HitBuilder +{ + Q_OBJECT +public: + static const QString SITE_ID; + static const QString ACTION_NAME; + static const QString ACTION_URL; + static const QString API_VERSION; + static const QString EVENT_CATEGORY; + static const QString EVENT_ACTION; + static const QString EVENT_NAME; + static const QString EVENT_VALUE; + static const QString RECORDING; +public: + MatomoBuilder(Context *context, QObject *parent=nullptr); + ~MatomoBuilder() override; + void initQuery() override; + void trackPage(const QString &path, const QString &title) override; + void trackEvent(const QString &category, const QString &action, const QString &label, const QString &value) override; +}; + diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp new file mode 100644 index 0000000..af08a4c --- /dev/null +++ b/src/plugin/plugin.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "plugin.h" +#include "analytics.h" + +#include <qqml.h> + +/*! + * \class Plugin + * \inmodule QtAnalytics + * \brief The Plugin class + */ + +/*! + * \brief register QtQuick types. + * \param uri the uri for the type registry + */ + +void Plugin::registerTypes(const char *uri) +{ + Q_UNUSED(uri) + // @uri analytics + qmlRegisterType<AnalyticsAttached>(); + qmlRegisterUncreatableType<Analytics>(uri, 1, 0, "Analytics", "No creatable"); +} + diff --git a/src/plugin/plugin.h b/src/plugin/plugin.h new file mode 100644 index 0000000..078556c --- /dev/null +++ b/src/plugin/plugin.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#pragma once + +#include <QQmlExtensionPlugin> + +class Plugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void registerTypes(const char *uri); +}; diff --git a/src/plugin/plugin.pri b/src/plugin/plugin.pri new file mode 100644 index 0000000..4938727 --- /dev/null +++ b/src/plugin/plugin.pri @@ -0,0 +1,20 @@ +QT += qml quick +CONFIG += c++11 + +SOURCES += \ + $$PWD/analytics.cpp \ + $$PWD/configutil.cpp \ + $$PWD/context.cpp \ + $$PWD/googlebuilder.cpp \ + $$PWD/hitbuilder.cpp \ + $$PWD/matomobuilder.cpp + +HEADERS += \ + $$PWD/analytics.h \ + $$PWD/configutil.h \ + $$PWD/context.h \ + $$PWD/googlebuilder.h \ + $$PWD/hitbuilder.h \ + $$PWD/matomobuilder.h + +INCLUDEPATH = $$PWD diff --git a/src/plugin/plugin.pro b/src/plugin/plugin.pro new file mode 100644 index 0000000..ecdc836 --- /dev/null +++ b/src/plugin/plugin.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib +TARGET = analytics +CONFIG += plugin + +TARGET = $$qtLibraryTarget($$TARGET) +uri = analytics + +include ( ../../qtanalytics.pri ) +include ( ../../doc/doc.pri ) +include ( plugin.pri ) +# Input +SOURCES += \ + plugin.cpp + +HEADERS += \ + plugin.h + +DISTFILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} + +qmldir.files = qmldir + +installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) +defined(ANALYTICS_DIR, var) { + installPath = $${ANALYTICS_DIR}/analytics + message( "The plugin will be installed in "$${ANALYTICS_DIR}/analytics ) +} + +qmldir.path = $$installPath +target.path = $$installPath +INSTALLS += target qmldir + +OBJECTS_DIR = .obj +MOC_DIR = .moc + diff --git a/src/plugin/qmldir b/src/plugin/qmldir new file mode 100644 index 0000000..28af2b9 --- /dev/null +++ b/src/plugin/qmldir @@ -0,0 +1,2 @@ +module analytics +plugin analytics diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..c42c58a --- /dev/null +++ b/src/src.pro @@ -0,0 +1,9 @@ +TEMPLATE = subdirs + +include ( ../qtanalytics.pri ) +include ( ../doc/doc.pri ) + +SUBDIRS += \ + plugin + + |