AlbertRosa
AlbertRosa

Reputation: 115

Is there a way to use google analytics to track calls to a json response?

I am working on a app that uses a json response from my Zend Framework 1.10 website. I want to track how many times the Json Action is hit?

If there is no true way to do this from just the action that is not reflected the json response.

Upvotes: 3

Views: 1609

Answers (3)

Davinj
Davinj

Reputation: 347

Just use the measurement protocol from the back end, create a hash and post it.

The following parameters are required for each payload:

https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide

v=1             // Version.
&tid=UA-XXXX-Y  // Tracking ID / Property ID.
&cid=555        // Anonymous Client ID.
&t=             // Hit Type.

p = {}
HTTParty.post('http://www.google-analytics.com/collect', body: p)

Upvotes: 0

tawfekov
tawfekov

Reputation: 5122

I would suppose you are using Jquery to illustrate my idea , I would track both success and error function of jquery using google analytics events

   example :  pageTracker._trackEvent(category, action, opt_label, opt_value );

  Guide : http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html



$.ajax({
......... some jquery code here .....

success:function(){
......... Jquery code ...........
/*lets show some magic */
pageTracker._trackEvent("JSON", "SUCCESS", "Loaded" , 1 );

},
error:function(){
.......... Jquery code ...........
pageTracker._trackEvent("JSON", "FAILD", "why it faild " , 0 );
}
})

at the end of the day , go to Events on you GA Account you would see handy results as you would expect :) you can track ( click , AJAX Request , Page load time , Banner & many other smart ideas )

another tip : you might use what GA Marketers used to do

this is the most easiest one to make http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55578 just append it to your AJAX request and watch the magic :)

Twitter using this idea in the mailing notification example :

http://twitter.com/*********?utm_campaign=newfollow20100823&utm_content=profile&utm_medium=email&utm_source=follow

Upvotes: 2

Alin P.
Alin P.

Reputation: 44346

You can track any action with GA by having a special page with tracking code for it that you load into an iframe when the action takes place.

If you need more actions you can have something like trackAction.php?action=myAction.

Regards, Alin

Upvotes: 1

Related Questions