gpt4 book ai didi

c++ - C++ 桌面应用程序中的 Google Analytics

转载 作者:太空狗 更新时间:2023-10-29 21:02:29 25 4
gpt4 key购买 nike

我正在尝试将 Google Analytics 跟踪添加到我的 C++/Qt 桌面应用程序中。为此,我按照此处指定的方式对 http://www.google-analytics.com/__utm.gif 进行了 http GET: http://automateeverything.tumblr.com/post/20500736298/google-analytics-without-javascript-or-cookies

我的网址是这样的:

http://www.google-analytics.com/__utm.gif?utmwv=5.2.5&utmac=UA-XXXXXXXX-1&utmhn=prot-on.com&utms=1&utmn=1763710005&utmcc=__utma%3D265465294.163654595.1362420921.1362420921.1362420921.1%3B&utmp=%2Freallyallheaders.html&utmcs=-&utmr=-&utmip=127.0.0.1&utmul=es-es&utmfl=-&utmje=-&utmsr=1920x1080&utmhid=957274494

这是我的源代码:

qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch()/1000;
if (this->timeOfFirstVisit == 0)
this->timeOfFirstVisit = currentTimestamp;
if (this->timeOfPreviousVisit == 0)
this->timeOfPreviousVisit = currentTimestamp;

QString googleAnalyticsRequestUrl;
QTextStream(&googleAnalyticsRequestUrl) << "http://www.google-analytics.com/__utm.gif"
<< "?utmwv=5.2.5"
<< "&utmac=" << TRACKING_ID
<< "&utmhn=" << HOST_NAME
<< "&utms=" << this->sessionNumberOfQueries
<< "&utmn=" << QString::number(qrand()) //this->generateRandomUTMN()
<< "&utmcc=__utma%3D" << this->domainHash
<< "." << this->sessionId
<< "." << this->timeOfFirstVisit
<< "." << this->timeOfPreviousVisit
<< "." << currentTimestamp
<< ".1%3B"
<< "&utmp=" << QString(QUrl::toPercentEncoding(pageUrl))
<< "&utmcs=-"
<< "&utmr=-"
<< "&utmip=127.0.0.1"
<< "&utmul=" + QLocale::system().name().toLower().replace("_", "-")
<< "&utmfl=-"
<< "&utmje=-"
<< "&utmsr=" + QString::number(QApplication::desktop()->screenGeometry().width()) + "x" + QString::number(QApplication::desktop()->screenGeometry().height())
<< "&utmhid=" + QString::number(qrand());

this->timeOfPreviousVisit = currentTimestamp;
this->updateSessionNumberOfQueries();

qDebug() << "Sending Google Analytics request: " << googleAnalyticsRequestUrl;

// Send a http GET request to the created URL
QNetworkAccessManager *manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply *)),this, SLOT(googleAnalyticsRequestReceived(QNetworkReply *)));
connect(manager, SIGNAL(finished(QNetworkReply *)),manager, SLOT(deleteLater()));

QUrl requestUrl(googleAnalyticsRequestUrl);
QNetworkRequest request(requestUrl);

// I see this headers with Firebug, but I think that they are not necessary
request.setRawHeader("Host", "www.google-analytics.com");
request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
request.setRawHeader("X-Forwarded-For", "127.0.0.1");
request.setRawHeader("Connection", "close");

manager->get(request);

但是我的页面访问量从未出现在我的 Google Analytics(分析)页面中...如果我做错了什么,你能告诉我吗?

最佳答案

遗憾的是,Google 没有可用的官方 Qt 库。但是,我建议您查看他们的 Google Analytics API(目前处于测试阶段)https://developers.google.com/analytics/devguides/collection/protocol/v1/这也表示即使您的请求无效且未正确处理,它也会始终返回 200。他们更有可能支持您使用此 beta API,然后对他们的 javascript 进行逆向工程以直接使用它。

编辑:同时查看您的代码,立即从 QUrl 开始并使用 http://harmattan-dev.nokia.com/docs/library/html/qt4/qurl.html#addQueryItem 添加查询项可能更明智。所以 Qt 会注意正确的编码等等。

关于c++ - C++ 桌面应用程序中的 Google Analytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15222038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com