I am sending a POST request to the Google analytics measurment protocol
at
https://www.google-analytics.com/collect?v=1&t=event&tid=UA-151666808-2&cid=123&el=cus&ea=CLIENT_REGISTRATION_SUCCESS3&ec=Server
However it is not being tracked on my site. I am sending it with Java API. I use rest template, feingClient, gama-client-core, google-analytics-java libraries. The result is always the same - the event does not track. If I change mine tid to another, then the event is displayed in another resource. Or if I call this link through POSTMAN, then the result is also successful.
The debug call for your request looks fine.
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ ],
"hit": "/debug/collect?v=1\u0026t=event\u0026tid=UA-151666808-2\u0026cid=123\u0026el=cus\u0026ea=CLIENT_REGISTRATION_SUCCESS3\u0026ec=Server"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
Data Processing time.
Check the real time api to ensure that the hits are being recorded if they are then you are all set. Then wait 24 - 48 hours for the data to complete processing you should see it in the standard reports then.
bot filtering
Make sure you have disabled bot filtering on the view
New google analytics account
It takes up to 72 hours for an account newly created in Google analytics to start showing data.
Quoted from google measurement protocol reference
Note that Google has libraries to identify real user agents. Hand crafting your own agent could break at any time.
You should change the request User-Agent to a browser like one so google doesn't think you are a bot.
Related
I am running an Azure Function on Java with EventHub trigger. Now the function receives 1000s of messages per min. It is becoming difficult to track your changes after deployment as the logs are showing one day old content. Now even though I have commented out certain lines and added other lines to verify my changes, after deployment it still shows the commented lines. When I observed it, those were old logs. Is there any way to change that? As I have to wait a long time to see my changes on kudu console.
Where do I change the settings, so that my changes will reflect on basis of current changes?
Update:
I am using below setup in host.json. So may be because of the property "initialOffsetOptions/type" my function is processing already processed events after each deployment. I have got this link Slow down EventHubTrigger in Azure Function but I am yet to test it. Any suggestion on this is welcome.
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"extensions": {
"eventHubs": {
"batchCheckpointFrequency": 5,
"eventProcessorOptions": {
"maxBatchSize": 256,
"prefetchCount": 512
},
"initialOffsetOptions": {
"type": "fromStart",
"enqueuedTimeUtc": ""
}
}
}
}
Now even though I have commented out certain lines and added other lines to verify my changes, after deployment it still shows the commented lines.
Make sure you check your deployment is done. And check for the Deployment history and last modified details of deployments in an Activity Log. (Resource Group -> Deployments -> Activity Log)
Is there any way to change that? As I have to wait a long time to see my changes on kudu console. Where do I change the settings, so that my changes will reflect on basis of current changes?
If you are using Consumption Plan, make sure you have to wait till your Function app restarts after deployment. After Deployment the Consumption Plan will take some time to sync the function trigger operation.
To avoid the problems, you can use the Premium App Service plan or enable Always On feature in your app service plan.
I implemented my backend service (using java and FCM) to send push-notifications to mobile apps.
I implemented my service using Java Firebase Admin-SDK (https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/messaging/package-summary and https://firebase.google.com/docs/cloud-messaging/send-message#java) about this and I'm able to send (and receive) push notifications on iOS and Android mobile apps.
Now I received a request from mobile-developers that they needs to customize (client-side) the received push notifications (also when the app is in background mode).
Probably here is reported a same question: What is the difference between Firebase push-notifications and FCM messages?
Reading the documentation (https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages) I understood that It's necessary to use a Data-message instead of a Notification message.
It's not clear for me what's necessary to change to support this delivery type.
Do I change the Android-config of the FCM-message or Do I remove some unnecessary data (just set all info into the custom data without others info for example Android configuration etc..)
It's possible to have a small example?
If your json will have notification key, developers will not able to handle notifications in background. They will receive this notification only when app is in foreground. In case when developers should receive “silent pushes” or they need control all notifications, you should remove notification key, and use only data key.
This can be achieved by changing the key 'notification' to 'data' as follows:
{
"notification": { //replace this line by "data"
"title": "Hey Gajanan",
"body": "Thanks for visiting omnidecoder.com"
},
"to" : "YOUR-GENERATED-TOKEN"
}
I am writing Java app which sends email via Amazon SES service, and that works fine. But now I need to retrieve email sending statistics as granural as per email ID basis.
So, I use CloudWatch and pass the notifications to SNS. Yet, I cannot infer away how to get the statistics as per explicit request to the Web service. The SNS endpoints are able to dispatch the data as on needing basis. When I want to make explicit request from my app on service for stats.
The S3 service is for storage. Do I need to store stats somehow on it, so that later I can query it?
Any resolutions and details are appretiated?
Hi For your requirement as per my understanding AWS Dynamo DB is the best way. AWS Dynamo DB is a No sql related DB. After sending email you can store the result (emailId, if you want time ect..) into Dynamo DB by using SNS, or nay lambda functions. You can fire a query to dynamo DB to get the statistics.
If you want to go with S3 bucket way, you have a maintain one json file, and each time need to overwrite that file.
Well, this is the way I got the sending stats.
When it comes to Amazon SES, it gives you very limited sending statistics; not pointing to particular sent email.
Then when it comes to Amazon Cloudwatch, it gives you very similar statistics as the SES, is that it gives you a chance to make the stats dates appear precise to the extend of minutes. Meaning that if you know when you sent the email, via SES, by storing it on DB, you can estimate which stat belongs to which email.
Then you can use the Amazon Firehose combined with Amazon S3. This is where I landed. The Firehose is a stream which pushes statistics on the S3 storage. The SES provides the configuration set which lets you attach it.
The S3 stores anything you like, including email sending statistics. You can have up to 5 stats:
Send
Delivered
Bounce
Complaint
Reject
The stats are stored in files which you can access and read by using Amazon's SDK pertaining to Java language.The way to query in Java
What you get then is JSON file of email sending statistics, e.g.,
{
"eventType":"Bounce",
"bounce":{
"bounceType":"Permanent",
"bounceSubType":"General",
"bouncedRecipients":[
{
"emailAddress":"recipient#example.com",
"action":"failed",
"status":"5.1.1",
"diagnosticCode":"smtp; 550 5.1.1 user unknown"
}
],
"timestamp":"2016-10-14T05:02:52.574Z",
"feedbackId":"EXAMPLE7c1923f27-ab0c24cb-5d9f-4e77-99b8-85e4cb3a33bb-000000",
"reportingMTA":"dsn; ses-example.com"
},
"mail":{
"timestamp":"2016-10-14T05:02:16.645Z",
"source":"sender#example.com",
"sourceArn":"arn:aws:ses:us-east-1:123456789012:identity/sender#example.com",
"sendingAccountId":"123456789012",
"messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000",
"destination":[
"recipient#example.com"
],
"headersTruncated":false,
"headers":[
{
"name":"From",
"value":"sender#example.com"
},
{
"name":"To",
"value":"recipient#example.com"
},
{
"name":"Subject",
"value":"Email Subject"
},
{
"name":"MIME-Version",
"value":"1.0"
},
{
"name":"Content-Type",
"value":"multipart/mixed; boundary=\"----=_Part_0_716996660.1476421336341\""
},
{
"name":"X-SES-MESSAGE-TAGS",
"value":"myCustomTag1=myCustomTagValue1, myCustomTag2=myCustomTagValue2"
}
],
"commonHeaders":{
"from":[
"sender#example.com"
],
"to":[
"recipient#example.com"
],
"messageId":"EXAMPLE7c191be45-e9aedb9a-02f9-4d12-a87d-dd0099a07f8a-000000",
"subject":"Email Subject"
},
"tags":{
"ses:configuration-set":[
"my-configuration-set"
],
"ses:source-ip":[
"192.0.2.0"
],
"ses:from-domain":[
"example.com"
],
"ses:caller-identity":[
"ses_user"
],
"myCustomTag1":[
"myCustomTagValue1"
],
"myCustomTag2":[
"myCustomTagValue2"
]
}
}
}
That is about it.
Requirement is to sync mails from Gmail for an user into our CRM. The system in place is based on Google Pub/Sub which watches inbox of the user for any change and fires the notification to our HTTPs endpoint. More on this at Gmail cloud pub/sub.
Based on the above procedure we git history of changes. And then i am interested in only new messages, so history.getMessagesAdded is preferred as per this guide. Issue we are facing now is the first mail of a thread is not captured under messagesAdded all the subsequent messages are passing through our system.
Note: For the first mail, we do get push from Google. But when we try to get Messages added it turns out empty. Is there anything special needs to be done for the first mail of the thread or am i missing out something.
I was experiencing a very similar problem, and my mistake was that I was using the historyId from the push notification, the solution was to store the last known historyId on my database, so, every time I get a notification, I get the history from the id I have stored, not the one from the notification.
In my case, the historyId from the notification doesn't even make part of the history, maybe because of my watch restrictions: labelIds=['INBOX']
This is the google pub/sub notification:
{
message:
{
data: {"emailAddress": "user#example.com", "historyId": "9876543210"},
message_id: "1234567890",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
I was using the message.data.historyId, wich was causing the confusion!
The message.data, comes as a base64 encoded string, in this example I just decoded it!
Step by step for watching new e-mails on the inbox:
Do all the configuration in the google pub/sub.
Start watching the user with the filters you want (docs.: https://developers.google.com/gmail/api/v1/reference/users/watch)
Store the historyId obtained in the step 2
When receive the notification, get all the events (history) using the stored id as the startHistoryId parameter (docs: https://developers.google.com/gmail/api/v1/reference/users/history/list)
In the history list obtained on the step 4, look for the new messages: history.getMessagesAdded().
Update the last known history id in your database, so you don't need to deal with the whole history every time!
I hope it helps.
I am thinking about keeping all registration ids(push token) in DB and sending notifications to user from iPhone. I tried something like this but did not get any notification.
func sendPNMessage() {
FIRMessaging.messaging().sendMessage(
["body": "hey"],
to: TOKEN_ID,
withMessageID: "1",
timeToLive: 108)
}
What I am doing wrong or maybe it is impossible at all?
Currently it's not possible to send messages from the application itself.
You can send messages from the Firebase Web Console, or from a custom server using the server-side APIs.
What you might want to do is to contact a server (like via http call) and that server will send the message to the user.
This way ensure that the API-KEY of the server is protected.
PS: the sendMessage(..) api is called upstream feature, and can be used to send messages from your app to your server, if you server has an XMPP connection with the FCM server.
Yes you can send push notification through Firebase.Please make sure do NOT include the server-key into your client. There are ways "for not so great people" to find it and do stuff... The Proper way to achieve that is for your client to instruct your app-server to send the notification.
You have to send a HTTP-Post to the Google-API-Endpoint.
You need the following headers:
Content-Type: application/json
Authorization: key={your_server_key}
You can obtain your server key within in the Firebase-Project.
HTTP-Post-Content: Sample
{
"notification": {
"title": "Notification Title",
"text": "The Text of the notification."
},
"project_id": "<your firebase-project-id",
"to":"the specific client-device-id"
}
Google Cloud Functions make it now possible send push notifications from device-to-device without an app server.
From the Google Cloud Functions documentation:
Developers can use Cloud Functions to keep users engaged and up to
date with relevant information about an app. Consider, for example, an
app that allows users to follow one another's activities in the app.
In such an app, a function triggered by Realtime Database writes to
store new followers could create Firebase Cloud Messaging (FCM)
notifications to let the appropriate users know that they have gained
new followers.
Example:
The function triggers on writes to the Realtime Database path where followers are stored.
The function composes a message to send via FCM.
FCM sends the notification message to the user's device.
Here is a demo project for sending device-to-device push notifications with Firebase and Google Cloud Functions.
Diego's answer is very accurate but there's also cloud functions from firebase it's very convenient to send notifications in every change in the db. For example let's say you're building chat application and sending notification in every new follower change.
This function sample is very good example.
For more information about cloud functions you can check official docs.
I have an app that has a "send feedback to developer" section. I also have a User collection in my firestore database. When a user logs into the app, I have that Users data update their FCM token with the following code in my SceneDelegate.swift:
import Firebase
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
authListener = Auth.auth().addStateDidChangeListener({ (auth, user) in
Auth.auth().removeStateDidChangeListener(self.authListener!)
if user != nil {
DispatchQueue.main.async {
let docRef = Firestore.firestore().collection("User").document((user?.email)!)
docRef.getDocument { (snapshot, error) in
guard let snapshot = snapshot else {return}
Messaging.messaging().token { token, error in
if let error = error {
print("Error fetching FCM registration token: \(error)")
} else if let token = token {
docRef.updateData(["FCMtoken":token])
print("FCM registration token: \(token)")
}
}
}
}
}
})
guard let _ = (scene as? UIWindowScene) else { return }
}
then in my feedback view controller i have this code to send my specific device (but you can look up/fetch which specific device you want in your database where the FCMtoken is stored where i have INSERT-DEVICE-TOKEN-HERE). The url to send to is "https://fcm.googleapis.com/fcm/send" and you can find YOUR-APP-FCM-KEY by going to your project settings in firebase, going to cloud messaging tab and its the server key.
func sendMePushNotification() {
let token = "INSERT-DEVICE-TOKEN-HERE"
if let url = URL(string: "https://fcm.googleapis.com/fcm/send") {
var request = URLRequest(url: url)
request.allHTTPHeaderFields = ["Content-Type":"application/json", "Authorization":"key=YOUR-APP-FCM-KEY"]
request.httpMethod = "POST"
request.httpBody = "{\"to\":\"\(token)\",\"notification\":{\"title\":\"Feedback Sent!\",\"body\":\"\(self.feedbackBox.text!)\",\"sound\":\"default\",\"badge\":\"1\"},\"data\": {\"customDataKey\": \"customDataValue\"}}".data(using: .utf8)
URLSession.shared.dataTask(with: request) { (data, urlresponse, error) in
if error != nil {
print("error")
} else {
print("Successfully sent!.....")
}
}.resume()
}
}
Use onesignal,you can send device to notifications or device to segments ,it can work with firebase in this way
Use onesignal functions to create a specific id,save it in a firebase database ,then when the id can be put in another function that is used to send a notification
Notes: 1-i am using it in my apps with firebase works perfectly
2-i can submit that code,just someone comments so i can find this answer