Appending GA event tracking to JSON element - php

I am trying to add event tracking to a product that is being translated to html cross-domain...
The file is located server-side and written in PHP. The JSON snippet that I need to append the GA event to is as follows:
"products": [
{
"title": "product",
"description": "description",
"thumbnail": "http://myurl.com/picture.jpg",
"price": "£1.99",
"url": "http://link.com"
},]
Now, reading up a little bit on this on this article has given me a bit of insight: Using google analytics to track hits on an XML web service
Would it be a matter of something as simple as this?
<?php
//Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com');
?>
"products": [
{
"title": "product",
"description": "description",
"thumbnail": "http://myurl.com/picture.jpg",
"price": "£1.99",
"url": "http://link.com"
},$ga->setEvent("Category", "Action", "Label", "Value");]

Sure, look at mit Github Project
https://github.com/ins0/google-measurement-php-client
it is a PHP client library to communicate with Google Analytics from server-side.
otherwise you can use other great repositorys, look here
https://github.com/search?q=google-measurement&source=cc

Related

Sending Json to Jira Api

I am trying to send a POST request to Jira API
Example Json
{
"fields": {
"project":
{
"key": "BAR"
},
"summary": "testttt",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Bug"
},
"priority" :{
"name" : "Low"
}
}
}
I am successfully making a POST request with postman to the API but I am struggling to make this POST request with Laravel.
I made a form in HTML where the admin must write some data like summary description issuetype and priority. I am accepting the data in the back end but I am having trouble how can I build such JSON with Laravel.
As you can see here
"issuetype": {
"name": "Bug"
}
name is nested in the issutype how can I explicitly create it to be ready to send into the API

Not getting JSON from wordpress

I am trying to make an android app for a wordpress website. But unable to get the JSON of post. I tried with two pluginsThese are the plugins of the website
for JSON
WP Rest API
JSON API
WP Rest API is returning this
[]
and JSON API is returning this
{
"status": "ok",
"count": 0,
"pages": 0,
"category": {
"id": 21,
"slug": "maths",
"title": "Maths",
"description": "",
"parent": 13,
"post_count": 3
},
"posts": []
}
According to me this problem is due to any other plugin. But I am unable to find the solution
API using for JSON
1. with JSON API plugin I am using this link http://iitianlogic.com/custom/get_category_posts/
and posting id=4
The request url is not correct, Please try the below url which showing posts under uncategorized category http://iitianlogic.com/api/core/get_category_posts/?slug=uncategorized
Hope this will work

Does Facebook Graph API Post Picture url (safe_image.php) expire?

I'm grabbing Facebook Post's pictures via Graph API call:
GET /mypageid/posts?fields=id,created_time,picture
Here's a sample response:
{
"data": [
{
"id": "1389378987988776_1745791089014229",
"created_time": "2016-08-03T21:55:39+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQBQL02u4kJtLNFs&w=130&h=130&url=fbstaging%3A%2F%2Fgraph.facebook.com%2Fstaging_resources%2FMDExNzQ1NzkwNjg5MDE0MjY5Ojk5ODEyOTY4Ng%3D%3D&cfs=1"
},
{
"id": "1389378987988776_1745301615729843",
"created_time": "2016-08-02T18:10:53+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQD7O17OAki29Gus&w=130&h=130&url=http%3A%2F%2Fcdn2.obsnocookie.com%2Fwp-content%2Fuploads%2F2015%2F03%2F13995025_770x433_acf_cropped.jpg&cfs=1"
}
}
Does the picture URL have an expiration date?
There is no specific expiration date afaik, but you should never rely on CDN links being available later according to Facebook. If you need them, you can download and store them on your own server.

PHP activity feed - similar to Facebook - How to convert response from json to HTML elements

We are building a activity stream kind of website very similar to facebook (in activity feed alone). For loading user's activity feed, we send the request to PHP file through AJAX method. Server file will handle the logic and return back the values as an array in JSON format. I wanted to know, is there any framework available to write the JSON response to HTML elements. Also, the fees are not similar. It will vary according to the type (Photo, Album, Status Updated, Shared, Liked, etc). So i need to load different template view for each of the activity feed. Actions will be common like Share, Comments for all feeds.
Can you please share which will be the best approach to load the content according to the data received. Also the content need to be refreshed periodically. I have pasted the sample JSON response below for reference:
{
"id": "1",
"picture": "",
"link": "http://www.google.com",
"name": "Srini updated status",
"description": "Lorem ipsum",
"actions": [
{
"name": "Share",
"link": "http://networkedblogs.com/hGWk3?a=share"
}
],
"type": "statusupdate",
"created_time": "2011-05-10T18:35:38+0000",
"updated_time": "2012-07-20T10:42:58+0000",
"likes": {
"count": 0
},
"comments": {
"data": [
{
"id": "19292868552_10150189643478553_22286888",
"from": {
"name": "Lorenzo Portillo",
"id": "613727863"
},
"message": "does anyone knows why i get a rhombus and '?' in my app description when I publish in a user's wall, instead of a letter with accent?!?!?!?!?!?",
"created_time": "2012-05-28T13:48:45+0000"
},
"count": 1
}
}
Need help / suggestions on how to design the template according to the json array in javascript. Any comments / code help will be more helpful.
Thanks in Advance,
Regards
Srinivasan.C
Well, if you consider making a very robust app, take a good look at emberjs.
You should also try jquery's (jquery mobile, jquery ui, jquery ajax)
You can create an html output in your php file when you are getting the response from the Facebook API. According to me you can do json operation easily in PHP. By using json_decode you get array and that you can traverse it and build an html as per your requirement.
Hope it helps

Inconsistency from Graph API

I'm currently writing a PHP application.
I noticed something strange when it wasn't returning the persons birthday.
To cut a long story short, when i manually query the graph api, it gives me the full result set (birthday, email etc. included). However, when I run it in my app, it comes back as if i've not sent the access token.
When I manually visit the address it produces:
{
"id": "507665705",
"name": "Ally Dewar",
"first_name": "Ally",
"last_name": "Dewar",
"link": "https://www.facebook.com/alastair.dewar",
"username": "alastair.dewar",
"birthday": "06/22/1990",
"location": {
"id": "113744028635772",
"name": "Greenock"
},
"gender": "male",
"email": "alastair\u0040alastairdewar.co.uk",
"timezone": 1,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-03-11T15:56:19+0000"
}
However, when my application makes the same request (exact same URL), it comes back with
{"id":"507665705","name":"Ally Dewar","first_name":"Ally","last_name":"Dewar","link":"http:\/\/www.facebook.com\/alastair.dewar","username":"alastair.dewar","gender":"male","email":"alastair\u0040alastairdewar.co.uk","locale":"en_GB"}
My instinct says it could be a setting within the facebook app, as it wasn't a problem beforehand.
EDIT: https://developers.facebook.com/bugs/412680422092698?browse=search_4f854dc037a2a5d12811839
Thanks for any advice.
Make sure you ask for all the permissions that you need and also remove the app and start again. Make sure you ddon't cache any of the responses as well.
How do you query the API? Graph Explorer or just manually open the link (graph.facebook.com/USER_ID) and pass the auth token generated by the app? Testing with the Graph Explorer won't help you with your problem as permissions etc are different.
As mentioned by Nobita, code helps. This is as much as I can advise considering the amount of data you're giving us.

Categories