Okay, so I setup a google analytics account for testing purposes. I have to work on some stuff and I'm testing things locally before pushing it to our live environment. Since the tracking has to be done if Javascript is off we use the php-ga-measurement-protocol library from theiconic.
This is the code I use:
$this->analytics = new Analytics(true, false);
$this->analytics->setClientId(filter_input(INPUT_COOKIE, 'gaClientId', FILTER_SANITIZE_STRING))
->setDebug(true)
->setDocumentHostName(getenv('HTTP_HOST'))
->setDocumentLocationUrl(getenv('HTTP_HOST') . getenv('REQUEST_URI'))
->setDocumentPath(getenv('REQUEST_URI'))
->setIpOverride(getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('REMOTE_ADDR'))
->setProtocolVersion('1')
->setTrackingId({TRACKING_ID})
->setUserAgentOverride(getenv('HTTP_USER_AGENT'))
->setUserLanguage(strtolower(substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, 5)));
The URL generated would look something like:
https://www.google-analytics.com/debug/collect?cid=g9m2nds3980dki4ia2rcivtjn3&dh={WEBSITE.LOCAL}&dl={WEBSITE.LOCAL}%2F&dp=%2F&uip=127.0.0.1&v=1&tid=|||&ua=Mozilla%2F5.0%20%28Windows%20NT%206.3%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F74.0.3729.157%20Safari%2F537.36&ul=en-us&dt={DOCUMENT_TITLE}
This is the response:
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ ],
"hit": "/debug/collect?cid=g9m2nds3980dki4ia2rcivtjn3\u0026dh={WEBSITE.LOCAL}\u0026dl={WEBSITE.LOCAL}%2F\u0026dp=%2F\u0026uip=127.0.0.1\u0026v=1\u0026tid=|||\u0026ua=Mozilla%2F5.0%20%28Windows%20NT%206.3%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F74.0.3729.157%20Safari%2F537.36\u0026ul=en-us\u0026dt={DOCUMENT_TITLE}?_anon_uip=127.0.0.0"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
However, going to my Google Analytics page, it doesn't show up an active user and I can't figure out why.
Isn't that the intended consequence of sending the hit with debug mode "on"? To validate that the hit is correctly formed, but not to actually record the hit and impact reporting? From your own code:
->setDebug(true)
"hit": "/debug/collect?cid=g9m2nd..."
From the Google hit validation documentation on the /debug/collect endpoint:
Important: hits sent to the Measurement Protocol Validation Server will not show up in reports. They are for debugging only.
Related
I have a frustrating issue with the Google Cloud Translate API.
I set up correctly the restriction of the key to some domains including *.example.com/ * (without blank space at the end)
I launch the script on the URL https://www.example.com/translate and i have the following message :
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_HTTP_REFERRER_BLOCKED",
"domain": "googleapis.com",
When i remove the restriction, everything works, but i need the restriction to avoid misuse/abuse.
Furthemore, i use this same API Key for others Google App API (Maps, Auth, etc) and it works perfectly from this domain...
So weird.
Do you have any ideas or any ways to investigate better this issue ?
How i can know the referrer Google sees ? (or any external service)
Thanks a lot !!
Edit :
PHP code :
require_once(APPPATH . "libraries/GoogleTranslate/vendor/autoload.php");
require_once(APPPATH . "libraries/GoogleTranslate/vendor/google/cloud-translate/src/V2/TranslateClient.php");
$translate = new TranslateClient([
'key' => 'xXXXx'
]);
// Translate text from english to french.
$result = $translate->translate('Hello world!', [
'target' => 'fr'
]);
echo $result['text'];
Full error message :
Type: Google\Cloud\Core\Exception\ServiceException
Message: {
"error": { "code": 403, "message": "Requests from referer
\u003cempty\u003e are blocked.",
"errors": [ { "message": "Requests from referer \u003cempty\u003e are blocked.", "domain": "global", "reason": "forbidden" } ],
"status": "PERMISSION_DENIED",
"details": [ { "#type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_HTTP_REFERRER_BLOCKED",
"domain": "googleapis.com",
"metadata": { "service": "translate.googleapis.com", "consumer": "projects/XXXXX" } } ] } }
Filename: htdocs/application/libraries/GoogleTranslate/vendor/google/cloud-core/src/RequestWrapper.php
Line Number: 368
I will leave here my insights discussed on the Public Issue Tracker.
The HTTP restriction is working as intended, but the referer is always empty because this is not set by default. However, it can be added manually, so instead of doing:
-$translate = new TranslateClient([
'key' => 'XXX'
]);
You need to specify the referrer:
-$translate = new TranslateClient([
'key' => '[API_KEY]',
'restOptions' => [
'headers' => [
'referer' => '*.[URL].com/*'
]
]
]);
You have to take into account that this type of requests can be sent from whatever computer (if you have the key) since you’re not restricting the domain where the request is made, only checking who is the referrer (and you can set it manually). Moreover, API clients that run on a web browser expose their API keys publicly; that’s why I recommend you to use service accounts instead. For more information: adding application restrictions.
Regarding the HTTP referer, this is basically a header field that, basically, the web browsers put to let the web page know where the user is coming from. For example, if you click the above link (HTTP referer) your referer field will be this page.
In summary, since you can put whatever referer in the header of a request, this is pretty similar to not having any type of restrictions. Indeed, it’s recommended to use service accounts. To solve this issue easily, add the referer manually in the headers as exposed in the code above.
I read the comments and you seem to be doing everything ok. I would recommend you to try:
This error message can appear because you set API restrictions in the API key, is this the case? Maybe you’re restricting this specific API.
If you aren’t setting any API restrictions, is it possible to try adding an IP instead of the domain just for testing purposes?
I had same issue with google translate but not with maps.
So maps works with referrer restriction, but translate does not.
The only solution I found, with a restriction in force, is setting up an IP restriction instead of the HTTP referrers (web sites).
I'm using the latest SendGrid PHP API. I can successfully create a Single Send using the API, and easily associate lists the Single Send should go to when it's eventually scheduled (by list ID). When I use the API to then update that Single Send to use different lists, the list changes are not reflected in the SendGrid dashboard - only name changes, etc. The API request is successful in code and when using Postman. SendGrid's API response to the update reflects my changes in what they return back to me. The Single Send is also in "draft mode" when I attempt this. The associated lists in the SendGrid dashboard never change.
API call to Single Send Update Endpoint (PATCH):
https://api.sendgrid.com/v3/marketing/singlesends/3ee0cd4e-62f7-21eb-8ee8-3a2e1ebc21ed
with param:
{
"name": "TESTER 2",
"send_to": {
"list_ids": [
"52ca8ad3f-9db1-4c2x-1f01-85beecbx94c2"
]
}
}
And SendGrid returns (202, successful response code):
{
"id": "3ee0cd4e-62f7-21eb-8ee8-3a2e1ebc21ed",
"name": "TESTER 2",
"status": "draft",
"categories": [],
"send_at": "2021-02-01T19:06:00Z",
"send_to": {
"list_ids": [
"52ca8ad3f-9db1-4c2x-1f01-85beecbx94c2"
],
"segment_ids": [],
"all": false
},
"updated_at": "2021-01-31T22:52:58Z",
"created_at": "2021-01-31T19:07:20Z",
"email_config": {
"subject": "Hello World",
"html_content": "Hello World!",
"plain_content": "Hello World!",
"generate_plain_content": false,
"editor": "code",
"suppression_group_id": null,
"custom_unsubscribe_url": "https://www.example.org/unsubscribe",
"sender_id": 1212111,
"ip_pool": null
}
}
But, the associated contact lists are not updated. Anyone have any suggestions? My only workaround is to simply delete the single send every time and just re-create it. I'm storing their ID's locally so this adds a bit more work on my end, but I'm not sure what else to do.
To anyone struggling with this, hopefully this will save you some time. The problem wasn't with the API at all, but with the SendGrid dashboard. You need to do a hard reload on the Single Send dashboard page to see your changes. The SendGrid dashboard is a SPA. Ugh.
I'm trying out IBM Watson Assistant. Ultimate goal is to integrate it with my custom PHP backend, via it's Watson Assistant's cURL API Endpoints (because there's no complete PHP SDK yet).
Let me tell what I did so far:
Imported a sample Workspace from a Training Data Set.
Then I tried this, and it works fine.
Then I tried that exact same thing via cURL API, I got a response like this: (The json output format beautified)
.
{
"intents": [
{
"intent": "locate_amenity",
"confidence": 0.999901008605957
}
],
"entities": [
{
"entity": "amenity",
"location": [
7,
10
],
"value": "gas",
"confidence": 1
}
],
"input": {
"text": "i need some gas"
},
"output": {
"text": [
"Hi. It looks like a nice drive today. What would you like me to do? "
],
"nodes_visited": [
"Start And Initialize Context"
],
"log_messages": []
},
"context": {
"conversation_id": "153c18ee-1015-4b6a-ae04-789e29bf4a05",
"system": {
"dialog_stack": [
{
"dialog_node": "root"
}
],
"dialog_turn_counter": 1,
"dialog_request_counter": 1,
"_node_output_map": {
"Start And Initialize Context": [
0,
0
]
},
"branch_exited": true,
"branch_exited_reason": "completed"
},
"AConoff": "off",
"lightonoff": "off",
"musiconoff": "off",
"appl_action": "",
"heateronoff": "off",
"volumeonoff": "off",
"wipersonoff": "off",
"default_counter": 0,
"previous_cuisine": "",
"previous_restaurant_date": "",
"previous_restaurant_time": ""
}
}
Now please let me understand 2 things here.
Question (1)
At this point, I was expecting the API to return with a message:
"There are gas stations nearby. Which one would you like to drive to?"
But why it doesn't. If then, how do I achieve it?
Question (2)
How do I properly reply back with "Go to number 5." so that the API understands I'm referring to the previous Call? (aka) How to I continue the dialog flow? (Note: I tried sending back with the previous "contexts", "entities", "intents", but it is somehow still recognised as a new message.)
Please share me an example of cURL call to follow up the previous message.
Since there's no complete PHP SDK yet, it is very hard for me to understand just by the cURL API calls. API Documentation does not explain to that details too. Please help.
Thank you all.
The message API for Watson Assistant is stateless. Everything that is needed to process a request is submitted as parameters. This includes the message itself, but also the context. The context holds the state about where in the dialog tree the conversation is. It could also hold information that is transferred from WA to the app, e.g., to process a client-side action. Or from the app to WA, e.g., with a record from a database.
Coming to your request:
Your dialog probably sends out that reponse when a new conversation is started. I see it is the same as in the "Try it out".
You would need to send a "Hi" or empty message first, wait for the reponse from WA, then send your "I need gas" together with the context data you received from WA. WHen you look into the details, you see the dialog stack, turn counter and more. The conversation ID is the identifier for that current chat.
With the above, WA's next response should be exactly like in the "Try it out" because you went down in the dialog tree.
Our site is tracking CC and other transaction just fine, but has a problem with EFT transactions.
I have established that we are writing to the socket that is listening for GA calls with the correct information (compared it to another action that is being tracked correctly).
I need some help debugging the issue and was wondering if there was anywhere on the GA interface that I could see attempted and failed calls?
The moment you see it in the interface it's by definition not a failed call so, no, but there is a debugger extension that writes errors (if any) to the browser console.
If you do your tracking serverside (as you are talking about sockets) you could log the outgoing tracking calls to a file and send them to the debug endpoint by inserting the word "debug" after the hostname (so this would look something like google-analytics.com/debug/collect?v=1&tid=.....).
The debug endpoint will return a json response that points out missing or invalid fields. Example response below:
{
"hitParsingResult": [ {
"valid": false,
"parserMessage": [ {
"messageType": "ERROR",
"description": "The value provided for parameter 'tid' is invalid. Please see http://..... for details.",
"messageCode": "VALUE_INVALID",
"parameter": "tid"
} ],
"hit": "/debug/collect?v=1\u0026_v=j41d\u0026a=335525335\u0026t=pageview\u0026_s=1\u0026dl=file%3A%2F%2F%2FUsers%2Fepierstorff%2FDesktop%2Ftest.html\u0026dp=http%3A%2F%2F%2FUsers%2Fepierstorff%2FDesktop%2Ftest.html\u0026ul=de\u0026de=windows-1252\u0026dt=OFfline\u0026sd=24-bit\u0026sr=2560x1440\u0026vp=2385x678\u0026je=0\u0026fl=21.0%20r0\u0026_u=QEAAAIABI~\u0026jid=2113413999\u0026cid=761062822.1461745183\u0026tid=UA-XXXXXX-X\u0026_r=1\u0026z=140208380"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
I'm sending the following request to the Google Datastore API, via the PHP client, and i'm getting a "503 Backend Error" without any other information. I tried the online client available here, but the error is the same. Maybe something is malformed on my request? The documentation wasn't very helpful:
{
"mode": "NON_TRANSACTIONAL",
"mutation": {
"upsert": [
{
"key": {
"path": [
{
"kind": "Log"
}
]
},
"properties": {
"event": {
"indexed": false,
"stringValue": "new_order"
},
"dataType": {
"indexed": false,
"stringValue": "test"
}
}
}
]
}
}
Any ideas of what might be causing this behavior? Or how to enable more detailed feedback from the API?
When you perform POST https://www.googleapis.com/datastore/<APIversion>/datasets/<datasetId>/commit, make sure that if you created your project using the old Admin Console that your datasetId in the URL is the App Engine application ID, and that if you created your project using the Developer Console, that your datasetId is the project ID you see in the Developer Console.
Also, if you created your project through the new Developer Console, try toggling the API on and off.
Finally, check that you are completing the OAuth flow properly, all your client ID info makes sense, and that you are setting up the right scopes, etc...