Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The solution is open a socket as I this PHP library makes: <a href="http://code.google.com/p/php-ga/source/browse/trunk/src/GoogleAnalytics/Internals/Request/HttpRequest.php#175" rel="nofollow">http://code.google.com/p/php-ga/source/browse/trunk/src/GoogleAnalytics/Internals/Request/HttpRequest.php#175</a></p> <p>I paste my source code:</p> <pre><code>GoogleAnalyticsManager::GoogleAnalyticsManager() : domainHash(this-&gt;generateDomainHash(HOST_NAME)), sessionId(qrand()), sessionNumberOfQueries(1), timeOfFirstVisit(0), timeOfPreviousVisit(0) { } void GoogleAnalyticsManager::sendPageVisit(const char *pageUrl) { QTcpSocket socket; socket.connectToHost("www.google-analytics.com", 80); socket.waitForConnected(); if (socket.state() != QAbstractSocket::ConnectedState) { qDebug() &lt;&lt; "Impossible to connect to www.google-analytics.com"; return; } qint64 currentTimestamp = QDateTime::currentMSecsSinceEpoch()/1000; if (this-&gt;timeOfFirstVisit == 0) this-&gt;timeOfFirstVisit = currentTimestamp; if (this-&gt;timeOfPreviousVisit == 0) this-&gt;timeOfPreviousVisit = currentTimestamp; QString googleAnalyticsRequest; QTextStream(&amp;googleAnalyticsRequest) &lt;&lt; "GET /__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()) &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()) &lt;&lt; " HTTP/1.0\r\n" &lt;&lt; "Host: www.google-analytics.com\r\n" &lt;&lt; "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0\r\n" &lt;&lt; "X-Forwarded-For: 127.0.0.1\r\n" &lt;&lt; "Connection: close\r\n\r\n\r\n"; this-&gt;timeOfPreviousVisit = currentTimestamp; this-&gt;updateSessionNumberOfQueries(); qDebug() &lt;&lt; "Sending Google Analytics request: " &lt;&lt; googleAnalyticsRequest; socket.write(googleAnalyticsRequest.toStdString().c_str()); socket.waitForBytesWritten(); socket.close(); } int GoogleAnalyticsManager::generateDomainHash(const QString &amp;domain) { int hash = 1; if (domain != NULL &amp;&amp; !domain.isEmpty()) { hash = 0; for (int pos = domain.length()-1; pos &gt;= 0; pos--) { int current = domain.at(pos).toAscii(); hash = ((hash &lt;&lt; 6) &amp; 0xfffffff) + current + (current &lt;&lt; 14); int leftMost7 = hash &amp; 0xfe00000; if(leftMost7 != 0) { hash ^= leftMost7 &gt;&gt; 21; } } } return hash; } void GoogleAnalyticsManager::updateSessionNumberOfQueries() { this-&gt;sessionNumberOfQueries++; if (this-&gt;sessionNumberOfQueries &gt; 500) { this-&gt;sessionId = qrand(); this-&gt;sessionNumberOfQueries = 1; this-&gt;timeOfFirstVisit = 0; this-&gt;timeOfPreviousVisit = 0; } } </code></pre>
 

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