google analytics api in php website - php

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.

Related

Google Analytics is not tracking every page

Google analytics is installed on my website. My website is built using Wordpress and using the plugin "Insert Headers and Footers" I pasted the code from Google Analytics. I can confirm that it works on some pages, but not all.
The website is an e-commerce store so not having the tracking on every page is making it hard to establish funnels.
I realized my e-commerce data was not being tracked so I researched the issue and learned about Google Tag Assistant. I installed this add-on and sure enough, no tags are reporting back for some of my store pages.
The below screenshot is from the Google Analytics report from the Tag Assistant. It shows that no tags are set on my page https://www.californiabeardco.com/store/ or https://www.californiabeardco.com/product/beard-oil/
The main site is https://www.californiabeardco.com
Interestingly, the analytics seem to work on the homepage and the cart/checkout pages, but not the store/product pages.
I'm really not sure what to do, I thought that the insert headers and footers plugin would insert the analytics code onto every page on my site.
I appreciate any insight you may have to offer, thanks!
Is there a particular event that isn't reporting that you are expecting to see?
Using the 'Google Analytics Debugger' Chrome extension, I can see that Google Analytics is initialized on each page and is reporting page views.
I think you recently added Google Analytical Code.Give it some time and Google will fix this. I added it in one of my site and my problem was same as you. I waited for 1-2 weeks until it resolved automatically.
Why can You just paste Google code to footer.php ? Other problem can be ajax pagination but this also can be fixed by refresh code after every ajax request.
Ps. And yes, sometimes You just must wait and Google will start working. You can check page source - if there is google code then it will start working, if not - You make something wrong.

Google Analytics PHP API : get reporting

I have a professional website using Google Analytics for metrics and I try to automatize one task I used to do manually but.. not able to understand if it's possible ?!
I just began to using the Google PHP client library to access the Google Analytics API on my website Test with the HelloAnalytics.php file is OK, I manage to connect and retrieve my data.
What i'm trying to do is :
Get all URLs viewed in the past 24H (what you can see when you navigate in the GA dashboard -> Behavior -> Site content -> All pages)
Combine those datas with my custom Definition which is in fact a special token i generate for every users on my website via PHP, then send it thought with Javascript and ga('set', 'mycustomdefinition', 'my token');
Is it possible ?
Many thanks in advance for your support !
Data under 24-48 hours old has probably not completed processing so I recommend not looking at data viewed in the last 24 hours it wont be correct. Other wise yes you can see this.
Assuming you mean custom Dimension yes you can extract custom dimensions and the page path in the same request.
You might want to have a look at the Dimensions & metrics explorer as well as the google analytics query explorer both will help you understand what data can be extracted from the API.

Custom display of posts of Facebook, Twitter, Linkedi and Google+ on your website

Is it possible to shows posts, feeds etc in a customized manner on your website? For example if I don't want to use the plugins they provide to embed on your website which show posts in a rectangular box I want to show posts from these social media sites in different manner. For reference please visit this website and scroll down to section below Latest News and Testimonials you will find Facebook, Twitter, LinkedIn and Google+ with Lorem Ipsum text. It seems like this website has also not implemented this feature (don't know if its possible with all social sites) but I am asking if you need to implement something like this is this possible? I have to implement it on a PHP website, if that helps. Thanks for your help in advance.
Although you're asking for something different than embedding, I still believe what you're looking for is "Embedding posts". Most social sites do not want you to rebuild their stream experience and put it somewhere else -- additionally, most content policies on these sites prohibits you from caching or storing posts because it can easily become a privacy issue. Finally, if you're pulling a lot of posts, frequently, from these services, you will encounter API call limits.
The following resources should get you started with properly embedding posts so you don't have to worry about how you're caching:
Google+
Facebook
Twitter
If you (really, really) wanted to build out your own solution you should do it client-side in JavaScript, not in PHP. For this, you would need to use the following APIs:
Google+ uses the Activity API
Facebook has the Graph/Feed API
Twitter has the Search/Get Tweets API pass from%3A[username] to get specific user Tweets
If you were to try doing this in PHP, it would be easier using client libraries and starting from sample code.
Google+ PHP example
Facebook PHP client library
Twitter PHP client libraries
Make sure that you're following the content policies of the various sites you're aggregating. In other words, if you're doing something like caching the results in a MySQL database pulled using your PHP script, invalidate the cache every 3600 seconds and every time a post is no longer retrieved from your API calls.

Three Google Analytics Codes on One Site?

I was wondering if it was possible to have two or more sets of Google Analytics tracking codes on one page. There's going to be a single webpage that is accessible through either normal methods (desktop or mobile browser), or accessed through scanning the QR code on the product packaging and being redirected that way.
The client wants three things tracked:
Analytics for the full page (all methods of connection)
Analytics for just those connected via normal methods
Analytics for those connected via QR code
I have already developed a means of differentiating the connection method, and switching the Google provided Javascript for 2 and 3.
So is this possible, to have two analytics codes on one page? I have checked all over, can't find an answer that is to the point.
Thanks in advance
A single analytics will report browser and OS used and the origin of traffic. Hence, there's no reason to use three cookies, three JS files when you can just generate a personalized report with the data you need
Don't use different trackers for this, use custom variables. Splitting it up loses you valuable insight into how different use cases navigate the site.
If anyone is ever looking for this:
http://www.publicinsite.com/qr-codes-google-analytics-track-mobile-devices/
That;s the best bet I think

Live Analytics User data in CMS or Framework

I'm trying to use analytics to determine content being served to visitors from a CMS. As far as I can tell there is no API for Google Analytics that allows you to retrieve a users browsing history.
I understand you can store this into the users session, or roll your own logging of user visits, but I'm more interested in analytics platforms that offer and interface to access this data.
Is anyone aware of an analytics platform that allows you to programmatically retrieve the users data?
The other important aspect would be whether the user data can still be retrieved even if the storing of that data is done asynchronously - which would be needed to keep web app responsive.
In analytics platform you have several solutions. The most common in open source is Piwik http://piwik.org/
It offers an API and js tracking systems : http://piwik.org/docs/javascript-tracking/
You can set this up indirectly in Google Analytics, by using funnels and goals. Set a few predetermined paths of website pages, and have the visitors walking these paths reach a goal.
Have a look at http://www.openwebanalytics.com/. A might be a little bit of overkill for your situation, but if you need a customized need, it should be the right fit. If you're a developer or have access to one then you're set.

Categories