我正在尝试将 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(分析)页面中......如果我做错了,你能说我吗?