Google Analytics with PHP FRAMEWORKS - php

At my company we tend to put Google Analytics on our sites to gather some basic statistics like page views, bounce rates and others.
Recently it has been decided that Analytics should be further harnessed to gain insight into how our websites fair in terms of hitting particular targets.
Now, when using PHP frameworks such as Laravel, much of the architecture out of the box is based on server side code.
One example: submitting a form
User submits a form and you track a successful form submission with Analytics, but if the form submits and then the server side validation fails, this is actually a failure.
My question:
How do you effectively use Google Analytics with a server side framework? If you're not using AJAX there isn't even a callback for the JavaScript code to use.
So, the only way you could track a success in most cases would be to have a page load event for a thank you page or something similar.
Further to this, if all your validation is server side, would you not end up having to nest any GA events with PHP code anyway?

You can use this Laravel Package to send custom events to Google Analytics in PHP:
https://github.com/irazasyed/laravel-gamp

Related

How to Build a realtime multiplayer game using action script (flash) and php backend

I wanted to build a real time multi player game using flash (action script 3) as front end and use php as back end language and mysql database. There are lot of posts and tutorials online, but nowhere I found an article which would suffice my requirement.
I thought of using smartfox server. But lately they are not supporting php backend technology. Here is the answer by their technical person.
http://www.smartfoxserver.com/forums/viewtopic.php?f=18&t=15791
This seemed to be a useful post, but it didn't give me complete information as to handle the game play with php back end.
http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
Do we have to use web sockets in front end. And how to handle the user's delay on the website. Also I am supposed to use Facebook Login to get more users on the game.
My game should have multiplayer feature just like this one on facebook.
https://apps.facebook.com/livepool/
Can someone suggest me on this please.

Is there a secure php-ajax code available?

On many places (Google, Yahoo, Stack Exchange... ) I found that Ajax coding (for example php+Ajax login system) is not, and cannot be secure enough. So many reserve about Ajax security, and nowhere you can find an example of secure Ajax code.
At the same time, all this sites (even Facebook, Twitter...) USES a lot of Ajax code, for registering and loging users, for commenting features etc. Seems like Top Secret matter.
So, could someone show an example of secure php-Ajax code ?
An AJAX request is just like a normal browser request, just in the background. So if you would normally have a login form that posts data to your checklogin.php, you can do the same with AJAX and its equally secure.
Another thing to keep in mind is with cross site javascript calls. This is used for example when you are creating apps on facebook to transfer data from/to your server. These request have to be signed to make sure the data is comming from a valid source. This is done by using a secret and public key. These sites use oauth to handle these request. You can also implement this in your own site, but for any regular authentication (login/post messages/etc) this will not be needed. Just code like you would if it were a regular request.

Sending data to the Google Analytics platform - in a pure PHP page?

I'm building an application, and I'd like to incorporate some stat tracking for each of the pages created. However, these pages are simply redirect pages using header() to different places, depending on what conditions have been met.
Rather then build my own stat tracking platform and incorporate it within PHP, I'd rather send traffic data to the Google Analytics platform. However, as the page exits via a header() alteration, I cannot print the normal Javascript code.
Is there anyway I can still have the page and query string traffic data sent to Google Analytics without using the standard script?
User's browser must make a request to Google's 1-pixel "tracking gif". There is google's solution for mobile web sites, where Javascript is not available. You can see it in the tracking code section of your google analytics settings pages. It is written for PHP. However, this pure-PHP solution just inserts <img> tag into the output. It won't work for you, since you're just making a redirect with HTTP headers.
So, there could be two solutions:
Make the redirect via META tag. Thus, you'll be able to track the redirect with either Javascript or PHP-based analytics code.
Try to fetch that 1x1 GIF from google server-side. However, this will screw lots of things in your Analytics. E.g. originating IP will be wrong, so all demographics will be wrong, you won't be able to pass cookies, etc. It will be most rudimentary tracking at best.
There's an official Google's PHP class "Server-Side Google Analytics PHP Client"
https://code.google.com/p/php-ga/

google analytics catch 22

I have a catch 22 situation here with the google analytics tracking code.
I have a form that upon submission submits data to an api.
We recently decided to record this submission as an ecommerce transaction with the google analytics tracking code. The transaction does not get recorded until the application get submitted and returns data from the api. This is because data from the api is included in the transaction.
The issue is that the form also autosaves data to a database so that if the form is not completely filled out and/or submitted an automated php script can pick it up later for submission to the api.
Now the catch 22
I need to find a way to implement this for the data that is submitted via the automated php script.
3 solutions that won't work
Submitting the the transaction on the serverside to ga. This is possible, but in this scenario all the data that google analytics collects from the client comes from the server which eliminates the whole purpose of using google analytics to begin with.
Submitting the transaction before the form is submitted. Remember we need to retrieve data from the api to submit in the transaction.
Saving information about the client to the database for including in headers when submitting the transaction on the serverside to google analytics. Something like this would probably work that is if I new all the information that google analytics collects about the client, how to spoof my ip address and had the time to build a solution like this.
Use AJAX for your auto-saves and use SUBMIT for the final update.
For option 3, you could use the Urchin tracking methods to simulate the data as it would be sent to Google Analytics, and instead send it to a local file which scrapes the request info and then sends it to Google when its done.
So, your JS code would look like this:
var pageTracker = _gat._getTracker("UA-XXXX-1");
pageTracker._setLocalServerMode(); //this disables external GA calls.
pageTracker._setLocalGifPath("/foo/bar.gif");
pageTracker._trackPageview(); //or your transaction calls
From looking at the URL request this makes against a regular __utm.gif request, it seems that the only important thing missing is the utmcc parameter, which appears to be a url-encoded version of the Google Analytics cookies. You'd want to track this as well (out of document.cookie, or on the server side), so that you could add it to the query string when you make your Google Analytics request. This is important because this is where the session and source information is stored; otherwise your tracking won't have context.
Then, on the server, bar.gif could rewrite to bar.php, which captures the query string and request headers that Google would have sent to its servers (of primary importance is the query string and the user agent string and the IP address); , and then adds whatever data it needs, then takes the resulting query string and makes a cURL request to the Google Analytics version of that URL, with spoofed headers for browser, etc.
Unless you can use asynchronous tracking code to send the data after the API returns the necessary bits of data, there is no sensible way. The method described above is good and all, but would still require you to spoof IPs to Google, as the IP is read from the incoming call and it would again be the server.
In my experience Google Analytics is not the correct tool for cases such as this (server side tracking).
There's a question about sending Google Analytics hits from the serverside at #1027660 that has several suggestions on how to generate a server-side click.
Whilst that contravenes your "can't do it this way #3", you might find it looks simple enough to be worth breaking that rule.
Good luck!

google analytics api in php website

I am creating a custom reporting website, where I want to show live data from google analytics and accordingly the data in my website will change. I want it to be automated and dynamic, like whenever the data changes in GA, i want it to be automatically changed in our website, which will be shown to our clients to show the performance of our websites.
I am guessing this can be achieved by some api calling from php, xml returned values and showing those data on our website along with images.
i would appreciate if anyone could give me more info on how to start working on this.
Google Analytics has an official API. They don't seem to have ready-made PHP examples, but the XML sources should be easy to query. Not sure how "live" GA's data is, though - it could be that it is not possible to do stuff live tracking of visitors.

Categories