Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Analytics in a C++ desktop application
    text
    copied!<p>I'm trying to add Google Analytics tracking to my C++/Qt desktop application. To do that, I'm making a http GET to <code>http://www.google-analytics.com/__utm.gif</code> as specified here: <a href="http://automateeverything.tumblr.com/post/20500736298/google-analytics-without-javascript-or-cookies" rel="nofollow">http://automateeverything.tumblr.com/post/20500736298/google-analytics-without-javascript-or-cookies</a></p> <p>My URL looks like:</p> <pre><code>http://www.google-analytics.com/__utm.gif?utmwv=5.2.5&amp;utmac=UA-XXXXXXXX-1&amp;utmhn=prot-on.com&amp;utms=1&amp;utmn=1763710005&amp;utmcc=__utma%3D265465294.163654595.1362420921.1362420921.1362420921.1%3B&amp;utmp=%2Freallyallheaders.html&amp;utmcs=-&amp;utmr=-&amp;utmip=127.0.0.1&amp;utmul=es-es&amp;utmfl=-&amp;utmje=-&amp;utmsr=1920x1080&amp;utmhid=957274494 </code></pre> <p>And this is my source code:</p> <pre><code>qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch()/1000; if (this-&gt;timeOfFirstVisit == 0) this-&gt;timeOfFirstVisit = currentTimestamp; if (this-&gt;timeOfPreviousVisit == 0) this-&gt;timeOfPreviousVisit = currentTimestamp; QString googleAnalyticsRequestUrl; QTextStream(&amp;googleAnalyticsRequestUrl) &lt;&lt; "http://www.google-analytics.com/__utm.gif" &lt;&lt; "?utmwv=5.2.5" &lt;&lt; "&amp;utmac=" &lt;&lt; TRACKING_ID &lt;&lt; "&amp;utmhn=" &lt;&lt; HOST_NAME &lt;&lt; "&amp;utms=" &lt;&lt; this-&gt;sessionNumberOfQueries &lt;&lt; "&amp;utmn=" &lt;&lt; QString::number(qrand()) //this-&gt;generateRandomUTMN() &lt;&lt; "&amp;utmcc=__utma%3D" &lt;&lt; this-&gt;domainHash &lt;&lt; "." &lt;&lt; this-&gt;sessionId &lt;&lt; "." &lt;&lt; this-&gt;timeOfFirstVisit &lt;&lt; "." &lt;&lt; this-&gt;timeOfPreviousVisit &lt;&lt; "." &lt;&lt; currentTimestamp &lt;&lt; ".1%3B" &lt;&lt; "&amp;utmp=" &lt;&lt; QString(QUrl::toPercentEncoding(pageUrl)) &lt;&lt; "&amp;utmcs=-" &lt;&lt; "&amp;utmr=-" &lt;&lt; "&amp;utmip=127.0.0.1" &lt;&lt; "&amp;utmul=" + QLocale::system().name().toLower().replace("_", "-") &lt;&lt; "&amp;utmfl=-" &lt;&lt; "&amp;utmje=-" &lt;&lt; "&amp;utmsr=" + QString::number(QApplication::desktop()-&gt;screenGeometry().width()) + "x" + QString::number(QApplication::desktop()-&gt;screenGeometry().height()) &lt;&lt; "&amp;utmhid=" + QString::number(qrand()); this-&gt;timeOfPreviousVisit = currentTimestamp; this-&gt;updateSessionNumberOfQueries(); qDebug() &lt;&lt; "Sending Google Analytics request: " &lt;&lt; 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-&gt;get(request); </code></pre> <p>But my page visits never appears in my Google Analytics page... Can you say me if I'm making something bad please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload