GithubHelp home page GithubHelp logo

itsmehara / qgamp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from achipa/qgamp

0.0 1.0 0.0 152 KB

Qt/QML interface for the Google Analytics Measurement Protocol

License: Apache License 2.0

QMake 4.58% QML 12.60% C++ 82.82%

qgamp's Introduction

QGAMP

QGAMP is a Qt/QML interface for the Google Analytics Measurement Protocol

Google provides a platform-independent HTTP API to process data - the Google Measurement Protocol

https://developers.google.com/analytics/devguides/collection/protocol/v1/

QGAMP is a C++ class (API) that provides a convenient API for Qt Applications to be able to use Google Analytics interfaces to review timings, events and general user interaction patterns from both C++ and QML.

It's cross platform, and able to report from all Qt-supported platforms (so far verified on Android, iOS and Linux).

The requests are issued asynchronously through a network request queue, so they would not interfere with normal operations of the application.

If operated offline, QGAMP can maintain a timestamped buffer, and replay that buffer (with the correct timestamps) when the application is started later when connectivity is restored. Note that the buffer size is limited and increasing it is not advised as Google Analytics will throttle clients if too many requests are issued in short periods of time.

Example:

= C++

#include "googlemp.h"
...
// QApplication level app name and version are used automatically in reports
qApp->setApplicationName("HelloQGAMP");
qApp->setApplicationVersion("1.0");
qApp->setOrganizationDomain("csipa.net");
qApp->setOrganizationName("qgamp");

// start session
GoogleMP::startSession(QDateTime::currentMSecsSinceEpoch());

GoogleMP::instance()->reportEvent("Test", "CPP_call", "1");

= QML

In main.cpp we need to initialize and register

static QObject *analytics_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
    Q_UNUSED(engine)
    Q_UNUSED(scriptEngine)

    GoogleMP *gmp = GoogleMP::instance();
    return gmp;
}

int main(int argc, char *argv[])
{
    ...
    qApp->setApplicationName("HelloQGAMP");
    qApp->setApplicationVersion("1.0");
    qApp->setOrganizationDomain("csipa.net");
    qApp->setOrganizationName("qgamp");

    GoogleMP::startSession(QDateTime::currentMSecsSinceEpoch());

    qmlRegisterSingletonType<GoogleMP>("MeasurementProtocol", 1, 0, "Analytics", analytics_singletontype_provider);
    ...
}

After this, we can inclue the following in the QML files:

import MeasurementProtocol 1.0

And then use the Analytics object to access all methods. Note that qgamp registers as a singleton, so you don't need to create analytics items, the Analytics object becomes available just by having the import statement

Component.onCompleted: {
    // A good way to time QML startup performance
    Analytics.reportTiming("startup_QML", false);

    // use showScreen to track user navigation
    // note: onCompleted is only good for first screen
    Analytics.showScreen("ApplicationWindow");
}

For a detailed example of mixes C++ and QML use of qgamp, take a look at the example directory

DISCLAIMER: This project is not written nor endorsed by Google. It does not contain any SDK or code from Google - it creates and executes all requests autonomously.

Google Analytics™ service is a trademark of Google Inc. Google and the Google logo are registered trademarks of Google Inc., used with permission.

qgamp's People

Contributors

achipa avatar

Watchers

Its Me Hara avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.