Posted by jonlindh 2 years 46 weeks ago
Hi,
I have been working on a mobile e-commerce site and wanted to use Google Analytics to track visitors and e-commerce values. I have seen a few examples of Google Analytics without Javascript but most of them creates a new cookie for each request, and the visitor data won't be that reliable. Therefore i made this PHP class...
The code generates a HTML-code with one or more images thats tracks the visit and e-commerce values. I have also used DeviceAtlas API to track the screen resolution and color depth.
The traffic source is still an issue, i guess search egines and referals won't work that well yet....
Let me know what you think and how this works for you :)
See the latest code below




Posted by jonlindh 2 years ago
Found a typo misstake in the function SetTransactionItem that I have corrected. See the correct code below:
Posted by Kristine 2 years ago
Motally (www.motally.com) has a great mobile analytics solution with a free version. It's easy to use; just cut and paste a few lines of code in a common header or footer and Motally does the rest. You'll get accurate data on page views, sessions, and unique users. You can even track specific events or do funnel analysis. Reports are easy to read and you can receive them through automated emails or log on to export them directly to you computer. Check it out at www.motally.com/demo
Feel free to contact me if you have any questions (kristine@motally.com).
Kristine
Posted by jonlindh 2 years ago
New version that handles referrals:
Posted by xyz 2 years ago
Hello,
it could be that this violates the Terms of Service of Google Analytics.
cf. http://www.google.com/analytics/tos.html
Posted by Noodles 2 years ago
I don't see how it would be a violation of Google's TOS.
Good work with the class Jon, but could you remove the hardcoding of the Analytics account number and website? Maybe pass them into the construct? This way I can use different account numbers if I need to.
Posted by Noodles 2 years ago
You might also want to consider replacing any &'s in the image URL with & to comply with xHTML standards.
Btw, I'm trying this on http://drugs.mobi. I will leave it for a couple of days and see if it improves our analytics numbers.
Posted by jonlindh 2 years ago
New version:
- Better traffic source tracking, added organic search and adwords
- I have moved the account number and host to the constructor
Posted by xyz 2 years ago
cf. GOOGLE ANALYTICS TERMS OF SERVICE
"You will not nor will You allow any third party to (i) copy, modify, adapt, translate or otherwise create derivative works of the Software or the Documentation; (ii) reverse engineer, de-compile, disassemble or otherwise attempt to discover the source code of the Software, except to the extent applicable laws specifically prohibit such restriction (iii) rent, sublicense, lease, sell, assign or otherwise transfer rights (or purport to do any of the same) in or to the GATC, the Processing Software, the Documentation or the Service; (iv) remove any proprietary notices or labels on the Software or which are otherwise placed by the Service; or (v) use, post, transmit or introduce any device, software or routine which interferes or attempts to interfere with the operation of the Service or the Software."
Posted by Richard Hearne 2 years ago
@XYZ - I don't think this code breaks TOS. All JonLindh is doing here is writing code to output the beacon to GA.
You'll find there are tonnes of third party developers building weird and wonderful stuff on top of GA.
@JonLindh - will check this out. It looks like a very interesting way to use GA in a mobile environment. Thanks for posting it here.
Posted by xyz 2 years ago
Hello,
unfortunately Google Analytics has no email contact option to ask if such a tracking code would be accepted.
A second issue could be that the server side construction of the utm.gif URL and the cookies could conflict with ga.js if one uses both tracking methods.
Posted by eduardocereto 2 years ago
hey jonlindh,
This is great code and might help us a lot. I still miss _setVar, but I can live with that for now. You should host this code somewhere like google code or bit bucket so we could more easyly track your changes or submit new patches.
Thanks for that work
Posted by eduardocereto 2 years ago
One more thing. I'm pretty sure the timestamps stored on google cookies are divided by 1k.
Sou you should store it like this:
Sure you should double check it. But I remember having problems with it in the past.
Posted by beatler 2 years ago
In case you cant use PHP, you can try with a public service:
<img src="http://nojsstats.appspot.com/UA-123456/mywebsite.com" />Documentation here.
Greets
Posted by Bensbury 2 years ago
Hi Jon,
I'd like to try out your script.
I can see quite a bit of cookie setting in the php, but many mobile devices don't support cookies.
Especially in Japan.
I'm not a php coder, so does the script work without cookies?
And if not would it be easy to convert it to work without cookies?
Thanks.
Posted by Sprize 2 years ago
http://www.acleon.co.uk/posts/galvanize-google-analytics-without-the-javascript/comment-page-1
Here's another good script. Don't think they are that different :)
Posted by mattan 2 years ago
And here's the script from google themselves: http://analytics.blogspot.com/2009/10/google-analytics-now-more-powerful.html
Posted by ruadhan 2 years ago
Mobile Champion
Brilliant! This should shake things up a bit.
Ruadhan O'DonoghuedotMobi
Posted by jonlindh 2 years ago
This is great, but it looks like e-commerce tracking function is missing. Hope they'll add it soon...
/Jon
Posted by garbetjie 2 years ago
Just thought I might throw this in here, but there's also the mobile analytics available from Admob -- http://analytics.admob.com. I'm not 100% sure how it would match up to GA, but I've been pretty stoked with the tracking I get from it.
Posted by Suma 2 years ago
http://www.project83.com/blog/installing-google-analytics-on-a-mobile-website/
Posted by CRUCIFER 2 years ago
Posted by garbetjie 2 years ago
Hey crucifier.
I've never had any hassles getting it working. The only modifications I've made to it is to integrate it into CakePHP (which is the PHP framework that I use). Other than that, I'm pretty much using it as it is given.
I'm using the cURL PHP snippet, if that's worth anything :)
Posted by benicoz 1 year ago
Hey,
I would like to track ecommerce transactions on a mobile website visited mostly with non javascript compatible devices.
I've found this thread and I thought I was saved but I don't get how to use and install the custom PHP class.
Now that google analytics for mobile is released, does that kind of custom code still work?
thanks for your help
Posted by mikehenry 17 weeks ago
Google analytics is really an informative and amazing topic which is beautifully discussed in the post, i liked it. tours in India
Posted by mikehenry 17 weeks ago
The Google is the most amazing and big search engine of the world and i am happy to read an amazing post about its analytics, it is really remarkable for me. tours in India
Posted by xiaopy12 1 week ago
Christian Louboutin Sale fdyey