Get the total earnings from a specific URL using the Adsense Management API - adsense

Is it possible to get the total all-time earnings of a specific URL (say, https://example.com/page/xyz) using the AdSense Management API? (preferably the PHP library).
If so, please post a code answer or atleast a concept of how it could be implemented.
BTW, the number of ad units or any specific ad units dont matter; I just want the total income from a specific URL on my site using the API

You can use URL Channels to declare the specific pages you want to track, and then in the API you can include the URL_CHANNEL_ID or URL_CHANNEL_NAME dimension in your report to break down by URL.
Once your URL Channels are set up, you can check out the AdSense API example repository to see how to run a report. This repository has different folders for different PHP versions. Choose the folder corresponding to your version, then go to examples/GenerateReport.php for a starting point. The AdSense API docs have a full list of Dimensions and Metrics and the full report specification in case you want to make other changes.

Related

How do I see in Google Analytics specific Facebook post exactly bringing me traffic?

I would like to see in analytics specific Facebook posts that are bringing traffic to the site. The 'Referrals' doesn't provide this info, but only shows how much traffic came from Facebook.com and m.facebook.com.
You can do this with the help of UTM Parameters.
What Makes Up a UTM Link?
Here’s my link for a test post
www.yourwebsite.com?utm_source=facebook&utm_medium=social&utm_campaign=post_name&utm_content=post_content
Now let’s break this link down, to understand what each metric means, and what it corresponds to in Google Analytics.
First, there is the “utm_source” value, which translates to the “source” dimension in Google Analytics. This is where traffic is coming from. You can name it whatever you want. In this example, my source is “facebook”
Equally as important is the medium, specifically “utm_medium,” which tells me what type of traffic this is. As this is from social media, I have named it social.
Easily the most important part of the link — “utm_campaign” — is the name of what you’re tracking, for example, “Summer Promotion.” Think of this as another way to roll up all the different posts and sources to see higher-level insights.
The next two metrics — “utm_term” and “utm_content” — are both optional and interchangeable. It’s about personal preference and how granular you want to get with your analysis.
If you don't want to build the URLs manually, you can use URL Builder from google.
Make sure you paste the full URL in the URL builder so that it populates the correct URL. Also make sure that you paste the whole URL created by URL builder with all UTM parameters on Facebook.
Hope this helps.

Cannot retrieve the reach estimate for some Facebook ads (from the API)

The API lacks some clear explanations on retrieving the reachestimate for either an ad account or an ad. I have made sure that:
I am an admin/ or added to a Facebook app
I have a paid advertising campaign
The adaccount ID is added in the Settings Advanced panel of the Developer App page
I've been trying to:
In Graph API Explorer, retrieve the data by query expansion: me?fields=adaccounts{campaigns{adsets{ads{reachestimate}}}}. However, I always get one of the following (randomly):
Still in the explorer, retrieve it by direct access: act_{adaccount_id}/reachestimate I get this, even if I am 100% sure the ad account is added in the Advanced Settings panel:
Both of 1 and 2 in the iOS project. I get this: com.facebook.sdk.core error 8
Test it by curl with the example from here. I get this (the same with the one from point 2): The ad account is not enabled for usage in Ads API.
Just as a further note, for point 1 that's not the whole query, but I didn't write the adjacent fields because they would've been redundant for the purpose of this question.
I simply need to retrieve the ad accounts, the campaigns, the ad sets and the reach estimate simultaneously in the same query. It seems like a dead spot for me. Do you have any suggestions? Can you show me a Graph API explorer working example? Or, if what I'm asking is impossible, can you simply show some code that works?
Are you app and ad account owned by the same person?
Facebook Ads API has tiered access. https://developers.facebook.com/docs/marketing-api/access
A newly registered app is in Development Tier and can only access the user's own ad accounts. You need to make some API calls on your own ad account for testing in order to get promoted to Basic Tier and manage other people's ad account.
Apparently, I got:
Please reduce the amount of data you're asking for, then retry your request.
Because the query was to broad. Those 'adjacent' fields actually triggered a massive query, so the solution was to either:
Put a limit(1) on the campaigns.
Individually retrieve the reachestimate for each adset.
I chose the latter because it suited my needs, but it's up to you which solution works better.

Testing Pagination of Facebook Graph API

I need to test that I can fetch subsequent pages of reviews from facebooks graph API.
The issue I have is that an account can only review a page once, and pagination doesn't kick in til there are over 100 reviews.
Do I really need to create 101 user accounts and have each one of them manually submit a review, just so I can be sure that when real companies use the software I'll be able to fetch the paginated results correctly?
Is there an alternative?
The issue I have is that an account can only review a page once, and pagination doesn't kick in til there are over 100 reviews.
That’s just the default limit for that endpoint - but you can specify a different limit in your initial query (simply via the parameter of the same name, /page/ratings?limit=3)
The prev/next links generated by the API then also use that limit value.
That way, you should be able to test pagination on smaller datasets as well.

Get page visitors from google analytics API

Reading Google Analytics API docs is like diving into Mariana Trench... so hoping to get some help here.
I have a website that users will visit one page per visit (most of the time). I've placed google analytics script on each page (can view reports in my GA account) and now want to write a "reporting page" on which to display information about "per page usage":
page1: 100 visitors, countries, OSes, ...
page2: 125 visitors, countries, OSes, ...
I want to get this info from API.
Could some one please point me to the right pages of the docs, from the very beginning?
For I can't understand even why I should use 2-step OAuth authorization there (or shouldn't I?) - since I'm writing this report for my own site on which I have already placed google scripts thus authorizing everything.
Thank you.
What i am thinking is that I could have a Webapplication with your pages listed. Web application itself is authenticating and querying the result on when user try to find statistics of particular page.
You should follow
1. Register Service account and get authentication key file
2. Register email account viewed in along clientid email a screen in google analytic users as admin level user
3. Use ga-dev-tools.appspot.com/explorer for query building
4.Implemenation needs
a) First Authenticate with the key
b) Get profile id and pass it to the fetching method
c) Fetch data of the query

Why is custom variable data in the Google Analytics Data Export API data different from my Google Analytics dashboard?

I have a custom variable defined on my site and the data is being recorded properly in my Google Analytics account. When I go to access the data via the Google Data Feed Query Explorer, the data I get isn't the same. Really, this is only the case with 'Visits' and any metrics calculated using it.
This is what I see in my dashboard:
http://www.screencast.com/t/QJl21ZOmpw
This is what I see in the query explorer:
http://www.screencast.com/t/WNGLiUUWum
I made sure the time frame matches and have pulled the same metrics. 'Hits' (aka pageviews) match up perfectly every time. Visits is obviously off and seems to be messing up other metrics that depend on it, such as 'Pages/Visit' (aka pageviews per visit).
I have reviewed the code and the custom variable is being set prior to recording the pageview. Am I missing something? My understanding is that Google Uses this exact same API to run their Analytics Dashboard, so why am I getting different data?
Try removing the visitors metric from your feed in the Query Explorer. A "Visitor" is different than a "Visit". I believe the stats of the Google Analytics screenshot have nothing to do with visitors. And including this metric might actually limit your result set to the unique visitors (I think).