Language Tracking with Server-Side Google Analytics - google-app-engine

I've ported the google analytics server side code over into my Python GAE application. Everything is working great, except for language tracking. I'm wondering if anyone here who has used google analytics on the server side has had success tracking languages.
The relevant bit of code is:
utm_url = utm_gif_location + "?" + \
"utmwv=" + GA_VERSION + \
"&utmn=" + str(randint(0, 0x7fffffff)) + \
"&utmhn=" + urllib.quote(domain) + \
"&utmsr=" + '-' + \
"&utme=" + '-' + \
"&utmr=" + urllib.quote(document_referer) + \
"&utmp=" + path + \
"&utmac=" + GA_ACCOUNT + \
"&utmcc=__utma%3D999.999.999.999.999.1%3B" + \
"&utmvid=" + visitor_id + \
"&utmip=" + ip
headers = {
'User-Agent': req.get('ua'),
'Accept-Language': req.get('lang')
}
httpresp = urlfetch.fetch(
url = utm_url,
method = urlfetch.GET,
headers = headers
)
if httpresp.status_code == 200:
logging.info("GA success: %s(%s)\n%s" % (utm_url, headers, httpresp.headers) )
else:
logging.warning("GA fail: %s %d" % (utm_url, httpresp.status_code) )
And here is a little debugging output which shows that I'm sending the Accept-Language header:
GA success: http://www.google-analytics.com/__utm.gif?utmwv=4.4sh&utmn=1306014991&utmhn=XXXXXXXXXXXXX.com&utmsr=-&utme=-&utmr=-&utmp=XXXXXXXXXXXXXXXXXXXXXXXXXX&utmac=MO-XXXXX-XX&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid=XXXXXXXXXXXXXXXXXX&utmip=XXX.XXX.XX.XX({'Accept-Language': u'en-us', 'User-Agent': u'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A405'})
{'content-length': '35', 'x-google-cache-control': 'remote-fetch', 'x-content-type-options': 'nosniff', 'age': '93451', 'expires': 'Wed, 19 Apr 2000 11:43:00 GMT', 'server': 'GFE/2.0', 'last-modified': 'Wed, 21 Jan 2004 19:51:30 GMT', 'via': 'HTTP/1.1 GWA', 'pragma': 'no-cache', 'cache-control': 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate', 'date': 'Wed, 22 Feb 2012 16:25:04 GMT', 'content-type': 'image/gif'}
(I've XXXX'd stuff to protect the innocent).
As I said, everything is working great (locations, hit count, user agent), except languages. They are all being counted as "not set".
Any ideas?

The language attribute that Google Analytics tracks isn't from headers.
Rather, it's passed directly in the URL request to __utm.gif as the utmul attribute.
So, my computer sets utmul=en-us, using the navigator.language or navigator.browserLanguage attributes (which it seems like it makes lower case.)
In your case, that means you just need to add this line to your __utm.gif constructions:
"&utmul=" + req.get('lang')

Related

Openssl library for interacting with POP3 local server inconsistency while retrieving response

Im working with on pop3 clinet using openSSL library. However I run to this incosistency problem, when reading from BIO socket, 4 times out of 5 there is "\r\n.\r\n" at the end, indicating end of multi-line response from server. But sometimes only "\r\n" is being returned for some reason, and the rest ".\r\n" appears in the next BIO_read. Buffer is not overflowing, it is set to 1024 length and this happens even in 604 characters long response.
Example:
+OK 555 octets
Return-Path: test1#mail.local
Received: from [127.0.0.1] (mail.local [127.0.0.1])
by LAPTOP-R30GIL79 with ESMTPA
; Wed, 20 Oct 2021 11:55:24 +0200
Message-ID: <dad24da8-dd91-62ed-3338-95fe46890c32#mail.local>
Date: Wed, 20 Oct 2021 11:55:24 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.2.0
Content-Language: sk
To: test1#mail.local
From: test1 <test1#mail.local>
Subject: testing
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Text testovacej spravy.
.
calling it exactly same after that results in:
+OK 555 octets
Return-Path: test1#mail.local
Received: from [127.0.0.1] (mail.local [127.0.0.1])
by LAPTOP-R30GIL79 with ESMTPA
; Wed, 20 Oct 2021 11:55:24 +0200
Message-ID: <dad24da8-dd91-62ed-3338-95fe46890c32#mail.local>
Date: Wed, 20 Oct 2021 11:55:24 +0200
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.2.0
Content-Language: sk
To: test1#mail.local
From: test1 <test1#mail.local>
Subject: testing
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Text testovacej spravy.
\r\n
As you can see ".\r\n" is missing for some reason. Octets does match but it disappear somehow. There are no memory leaks. This is function Im using for reading BIO socket
int readBIO(){
memset(buf, 0, strlen(buf));
int x = BIO_read(bio,buf,BUFF_SIZE);
if (x == 0 )
{
fprintf(stderr, "Error: Trying to read from closed connection.\n");
freeAll();
exit(1);
}else if(x < 0){
if (! BIO_should_retry(bio))
{
fprintf(stderr, "Error: Reading from bio socked has failed.\n");
freeAll();
exit(1);
}
}
if (checkResponse() != 0)
{
fprintf(stderr, "Error: Incorrect command / typo in command detected.\n Or wrong username / password has been entered.\n Server responded with -ERR.\n");
freeAll();
exit(1);
}
return 0;
}
Anyone might have an idea why this is happening?

I am not able to fetch response from server in ReactJS (SOAP). I tried using both fetch and XMLHttpRequest

I am trying to integrate fedex api's into ReactJS or rather NextJS Application. So far I have tried using fetch and XMLHttpRequest. Below is the code that I tried using XHR:
let XHR = new XMLHttpRequest();
XHR.open('POST', 'https://wsbeta.fedex.com:443/web-services', true);
let soapData = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v8="http://fedex.com/ws/vacs/v8">' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<v8:ServiceAvailabilityRequest>' +
'<v8:WebAuthenticationDetail>' +
'<v8:ParentCredential>' +
'<v8:Key>XXXXX</v8:Key>' +
'<v8:Password> XXXX</v8:Password>' +
'</v8:ParentCredential>' +
'<v8:UserCredential>' +
'<v8:Key> XXXXX</v8:Key>' +
'<v8:Password> XXXXX</v8:Password>' +
'</v8:UserCredential>' +
'</v8:WebAuthenticationDetail>' +
'<v8:ClientDetail>' +
'<v8:AccountNumber> XXXX </v8:AccountNumber>' +
'<v8:MeterNumber> XXXXX</v8:MeterNumber>' +
'<v8:Localization>' +
'<v8:LanguageCode>EN</v8:LanguageCode>' +
'<v8:LocaleCode>US</v8:LocaleCode>' +
'</v8:Localization>' +
'</v8:ClientDetail>' +
'<v8:TransactionDetail>' +
'<v8:CustomerTransactionId>Services Avaibility</v8:CustomerTransactionId>' +
'</v8:TransactionDetail>' +
'<v8:Version>' +
'<v8:ServiceId>vacs</v8:ServiceId>' +
'<v8:Major>8</v8:Major>' +
'<v8:Intermediate>0</v8:Intermediate>' +
'<v8:Minor>0</v8:Minor>' +
'</v8:Version>' +
'<v8:Origin>' +
'<v8:PostalCode>400061</v8:PostalCode>' +
'<v8:CountryCode>IN</v8:CountryCode>' +
'</v8:Origin>' +
'<v8:Destination>' +
'<v8:PostalCode>560055</v8:PostalCode>' +
'<v8:CountryCode>IN</v8:CountryCode>' +
'</v8:Destination>' +
'<v8:ShipDate>2019-05-21</v8:ShipDate>' +
'<v8:CarrierCode>FDXE</v8:CarrierCode>' +
'</v8:ServiceAvailabilityRequest>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
XHR.setRequestHeader('Content-Type', 'text/xml');
XHR.setRequestHeader('Access-Control-Allow-origin', '*')
XHR.onreadystatechange = function() {
if(XHR.readyState == 4) {
if(XHR.status == 200) {
console.log(soapData)
}
}
}
XHR.send(soapData)
I get different HTTP error for e.g. (405, 501, 400). Along with this I am getting CORS error which is as follows:
Access to XMLHttpRequest at 'https://wsbeta.fedex.com/web-services' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
For CORS I have tried mode cors in fetch request and with XHR I have set header to Access-Control-Allow-Origin as *, but I am still getting the same error.
I have also installed the extension from chrome web store which has solved the CORS problem yesterday but today I am again facing the same. I have tried to uninstall and reinstall the extension already.
I have also tried adding
Any help would be appreciated.

Gmail API to send an inline images

How can i send an inline images using Google API, here is my sameple code
Kindy let me know what am i missing ?
String email =
"Content-Type: multipart/related; boundary:\"multipart_related_boundary\"\r\n" +
"MIME-Version: 1.0\r\n" +
FROM_ME +
TO + toAddress + "\r\n" +
SUBJECT + "welcome" + "\r\n"
+ "--multipart_related_boundary" + "\r\n" +
"Content-type: image/gif; name=\"083.gif\"\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-ID: <083.gif>\r\n" +
"Content-Disposition: inline\r\n"
+ "--multipart_related_boundary" + "\r\n" +
"MIME-Version: 1.0\r\n" +
"Content-Type: text/html; charset=utf-8\r\n" +
CONTENT_TRANSFER_ENCODING_QUOTED_PRINTABLE +
"<html><body><img src=\"cid:083.gif\"/> welcome " +
"</body></html>\r\n\r\n";
byte[] converted = Base64.encodeBase64(email.getBytes());
String encodedStr = new String(converted);
encodedStr = encodedStr.replace("/", "_").replace("+", "-");
MediaType mediaType = MediaType.parse(APPLICATION_JSON);
RequestBody body = RequestBody.create(mediaType, RAW + encodedStr + END_BRACKET);
Request request = new Request.Builder()
.url(HTTPS_WWW_GOOGLEAPIS_COM_GMAIL_V1_USERS_ME_MESSAGES_SEND).post(body)
.addHeader(AUTHORIZATION,
BEARER + gmailAuthService.getRefreshToken(token).getAccessToken())
.addHeader(CONTENT_TYPE, "multipart/related; boundary:\"multipart_related_boundary\"").build();
Response response = okHttpClient.newCall(request).execute();
Finally in my gmail, i am not able to seethe inline image.
You are including the image section of your MIME message, but not the image itself.
After the Content-ID: <083.gif> and Content-Disposition: inline headers you need to include the actual image. Specifically, you probably want to add a Content-Transfer-Encoding: base64 header to that section and include a base64 encoded image payload.
An easy way to see how it could/should work is to use Gmail to email yourself a short test email with a small image. Then, in Gmail (Web UI) go to the message options (near the Reply button) and select "Show Original". That will show you exactly how the MIME message is built.

Azure upload blob 403

I'm trying to upload file on one of my Azure containers
this is one of my request send with ajax:
headers: Object
Authorization: "SharedKey MYACCOUNT:ENC_KEY"
Content-Type: "application/octet-stream"
data: File
x-ms-blob-type: "BlockBlob"
x-ms-date: "Mon, 19 Oct 2015 13:54:53 GMT"
x-ms-version: "2009-09-19"
type: "PUT"
url: "https://MYACCOUNT.blob.core.windows.net/data-test"
for the ENC_KEY I use :
authorizationHeader =
compute: (options, xhrOptions) ->
sig = #_computeSignature(options, xhrOptions)
result = 'SharedKey ' + options.storageAccount + ':' + sig
result
_computeSignature: (options, xhrOptions) ->
sigString = #_getSignatureString(options, xhrOptions)
key = CryptoJS.enc.Base64.parse(options.primaryKey)
hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key)
hmac.update sigString
hash = hmac.finalize()
result = hash.toString(CryptoJS.enc.Base64)
result
any ideas?
EDIT :
all code for authorizationHeader ->
https://gist.github.com/F4Ke/88debcede3b7e2312b11
2)
ERROR RESPONSE :
PUT https://MYACCOUNT.blob.core.windows.net/data-test 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
3)
#_getCanonicalizedHeadersString
itemcreation.coffee:232 x-ms-blob-type:BlockBlob
x-ms-date:Mon, 19 Oct 2015 14:33:15 GMT
x-ms-version:2009-09-19
#_getSignatureString
PUT
application/octet-stream
x-ms-blob-type:BlockBlob
x-ms-date:Mon, 19 Oct 2015 14:35:19 GMT
x-ms-version:2009-09-19
/MYACCOUNT/MYACCOUNT.blob.core.windows.net/data-test
The REST documentation describing how to sign a message can be found here. You can also take a look at the node shared key implementation hhere - might also help you...

Content-Type of Rest Api returning Null in salesforce

i am trying to call this rest api method
#HttpGet
global static String retrievingNotificationSettings(){
RestRequest req=RestContext.request;
RestResponse res=RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
if(req.headers.get('Content-Type').equals('application/xml'))
{
Map<String, SObjectField> fields = Notification_Settings__c.SObjectType.getDescribe().fields.getMap();
Schema.sObjectField T ;
Notification_Settings__c ss;
return 'hello World';
}
if(req.headers.get('Content-Type').equals('application/json'))
return System.JSON.serialize(note);
return null;
My request is
GET /services/apexrest/v.9/notifications/preferences/ritesh HTTP/1.1
X-HostCommonName:
ap1.salesforce.com
Authorization:
OAuth 00D90000000j9AW!AQkAQLba73cDzjXhQ4kkQ2PSru4XpFuJcwr5kg_W_MkZmQnm9vI653FBWeJaABwClQqtJZD_b6j7V0O_elkzvkh7IqRKSUop
X-PrettyPrint:
1
Host:ap1.salesforce.com
X-Target-URI:
https://ap1.salesforce.com
Content-Type: application/json
Connection:Keep-Alive
and the response i am getting is
HTTP/1.1 500 Internal Server Error
Date:
Fri, 25 Jan 2013 16:30:21 GMT
Content-Length:
203
Connection:
close
Content-Type:
application/json; charset=UTF-8
Server:
[
{
"message": "System.NullPointerException: Attempt to de-reference a null object\n\nClass.NotificationRestService.retrievingNotificationSettings: line 34, column 1",
"errorCode": "APEX_ERROR"
}
]
the line where i am getting error is
if(req.headers.get('Content-Type').equals('application/xml'))
i didn't understand why i am getting this error when in header i am passing value Content-Type as application/json ?? please tell me where i am making mistake
Can you System.debug(req.headers) to see if it was passed correctly?
To answer your null pointer question literally - use == instead of equals:
if(req.headers.get('Content-Type') == 'application/xml')
but that won't solve the real underlying problem.
You might want to try with different header (stupid, I know) or decide to add a GET parameter, something like &mode=json

Resources