Google Ads Get Campaign ads spends based on date and all states of USA - google-ads-api

I have many campaigns and I want to summarize the spends by all the states (USA states) and based on from and to dates.
I went through the https://developers.google.com/google-ads/api/docs/reporting/overview but I dont see any point that can determine the spends based on states.
Which endpoint I need to use in Google Ads API: In the FB I am using https://graph.facebook.com/v13.0/act_2264578877108750/insights?access_token=<ACCESS_TOKEN>&fields=spend&breakdowns=region%2Ccountry&level=ad&time_range=%7B%27since%27%3A%272022-05-15%27%2C%27until%27%3A%272022-05-15%27%7D&limit=100&after=OTkZD
Any help is really appreciated.

Reporting in the Ads API works by defining a query in GAQL that describes the data you want to obtain. For your use case, a possible query would look something like this:
SELECT
campaign.name,
segments.geo_target_state,
metrics.cost_micros
FROM geographic_view
WHERE
geographic_view.location_type = LOCATION_OF_PRESENCE
AND segments.date BETWEEN 20220101 AND 20220430
This will return rows for every combination of campaign name and state with the respective spend, while the WHERE clause makes sure that the use actually was in that state when the click happened—as opposed to somebody being interested in it.
Note that segments.geo_target_state will be returned as an ID, you can find the reference data here. Additionally, metrics.cost_micros will be returned in millionth of the base currency of the accounts, i.e. you'll need to multiply the value by 1'000'000.
About which endpoint to use: REST isn't recommended by Google (you should rather be using gRPC via a client library), but this here should work:
curl "https://googleads.googleapis.com/v10/customers/${CUSTOMER_ID}/googleAds:searchStream" \
--header "Content-Type: application/json" \
--header "developer-token: ${DEVELOPER_TOKEN}" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"query": "
SELECT
campaign.name,
segments.geo_target_state,
metrics.cost_micros
FROM geographic_view
WHERE
geographic_view.location_type = LOCATION_OF_PRESENCE
AND segments.date BETWEEN 20220101 AND 20220430
"
}'

Related

How to retrieve superclass (subClassOf) identifiers (not labels) from OBO ontology using ROBOT?

I am currently running the ROBOT snippet
robot export --input data/cl.owl \
--header "ID|LABEL|IAO_0000115|hasDbXref|subClassOf" \
--export results/cl.csv
To retrieve entries from the Cell Ontology. Currently it retrieves something like:
CL:0000036,epithelial fate stem cell,,,single fate stem cell
Where "single fate stem cell" is the parent. Is there any way to retrieve the CL identifier instead of the label?
See the documentation on rendering cell values in the ROBOT documentation:
http://robot.obolibrary.org/export.html#rendering-cell-values
Specifically, you can affix [ID] onto the column descriptor, i.e. SubClass Of [ID]
So the command would look like this:
robot export --input data/cl.owl \
--header "ID|LABEL|IAO_0000115|hasDbXref|subClassOf [ID]" \
--export results/cl.csv
Which will give the desired result.

Twilio ratelimit implementation is not seems working

Doc: https://www.twilio.com/docs/verify/api/service-rate-limit-buckets
The doc is not well explained the bottom queries.
1.created ratelimit with the unique name as 'phone_number'
twilio api:verify:v2:services:rate-limits:create \
--service-sid VAxxxxxxxxxxxx \
--description "Limit verifications by End User phone_number" \
--unique-name "phone_number"
Note: --unique-name i have passed as 'phone_number' static string not actual user phone number.. because '+' not allowed also https://www.twilio.com/docs/verify/api/programmable-rate-limits?code-sample=code-start-a-verification-with-a-rate-limit&code-language=Node.js&code-sdk-version=3.x#selecting-properties-to-rate-limit states it is static text combinations
previously i have used my phone number without + symbol.
2.Step 2
created a bucket with max 4 and duration 60
twilio api:verify:v2:services:rate-limits:buckets:create \
--service-sid VAxxxxxxxxxxxxxxxxxxxxxxxxxx \
--rate-limit-sid RK7xxxxxxxxxxxxxxxxxxxxx \
--max 4 \
--interval 60
After this bucket creation i expect to limit the sms sending for all the user based on users phone number ( in 60 second only 4 sms will be send for a user).
But what i can experience that i am receiving all sms which i created message.create().. ratelimit is not seems working..
Q1.is there any issue with the unique name as static text 'phone_number' what i can see is there is no combination of 'phone_number' and
'phone_number_country_code' ?
Ex:--unique-name "phone_number_country_code_and_phone_number"
or unique-name is a parameter that we need to send actual mobile of user?
Q2.if created one bucket with max: 4 duration: 60
second, then in 60 second only 4 sms will be send per user ?
Q3.one bucket and one rate limit enough for an application to handle all
users ?
Q4.if the above step is wrong what is the flow of implementation of this apis?
Q5.3rd api is showing in the doc is send verifications api, is this api is necessary when implementing ratelimits (i assume only create rate-limit and bucket create api are sufficient to enable ratelimit) ?
Q6.if i set bucket max: 4 and duration: 60 , what happen to the 5th sms is scheduled for that user (ex: 5th otp ) is that will deliver in same interval or the next intervel or it will discarded ?
or
let me know the actual sequential flow of ratelimit apis to accomplish the ratelimit to apply to all users. limit: 4 sms per user for specific 60 second interval.
Did you implement the send verification API with the ratelimit option using the unique-name property of the ratelimit?
twilio api:verify:v2:services:verifications:create \
--service-sid VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--rate-limits "{\"phone_number\": \"1234567890\"}" \
--to to \
--channel channel
As I understand it, the purpose of the rate limit is to limit the verification messages. I think the idea is that you create a rate limit and then apply it to a bucket, like you demonstrated. THEN you apply that limit to the verification service using the unique uniqueName and the phone number.

How to limit the number of results at the tag level using pup?

In brief:
Is there a way using pup to limit the number of results not overall, but at the tag level?
Backstory/use-case:
Ever since I learned about pup I've been obsessed. I'm constantly thinking of new use cases. This morning I wanted to use it to grab the latest headlines from ESPN.
ESPN seems to have an unordered list like this: <ul class="headlines"> and then a bunch of list items.
A simple solution would be:
$ curl -s -S http://espn.go.com/ | pup .headlines a text{}
right? But, as you can see, there are sometimes multiple links to each topic per line with alternate authors, so then you end up with results like "Low", "Anande", "Stark", and "Dinich" (last names of ESPN authors).
Ideally I'd like to do something like this:
$ curl -s -S http://espn.go.com/ | pup .headlines li a slice{:1} text{}
but that only returns the first result. :\
There are multiple <a> tags per <li>, so I'd like to retrieve all of the <li> items, but limit the number of <a> tags to 1 per <li>. Is this possible?
$ curl -s -S http://espn.go.com/ | pup '.headlines li a:first-of-type text{}'

Neo4j - traversal to find friends of friends that are not friends with the user yet

Using Neo4j 2.0.1, I'm trying to find friends of friends that are not friends with the user yet at depth of any level(2-5).
At first, I used cypher to get all friends of friends but sadly the performance was so bad when I tried to find friends of friends at depth of 4 and 5. So, I moved from cypher to traversal rest api and later I will use in Neo4jPHP traversal. So this is the change I made:
Note:
- there are 10 users with 5 friends of each user
- user that I want to traverse at depth of 3 is 1
- traversal at depth of 3
Friends List:
User | Friends
1 | 9,2,8,7,5
2 | 1,6,3,8,10
3 | 5,7,1,10,2
4 | 3,10,6,9,5
5 | 4,8,1,9,3
6 | 7,9,3,2,10
7 | 9,5,10,6,8
8 | 6,9,1,10,5
9 | 6,5,10,1,8
10 | 8,6,4,5,9
Cypher:
MATCH (U:User)-[F:Friend]->(FU:User)-[FF:Friend]->(FFU:User)
WHERE U.user_id=1
WITH DISTINCT U, FFU
WHERE FFU<>U
WITH DISTINCT U, FFU
MATCH (FFU:User)-[FFF:Friend]->(FFFU:User)
WHERE FFFU<>U AND NOT (U)-[:Friend]->(FFFU)
RETURN DISTINCT FFFU.username;
Travesal Rest Api[UPDATED]:
POST http://localhost:7474/db/data/node/1/traverse/node
{
"order" : "breadth_first",
"uniqueness" : "node_global",
"prune_evaluator" : {
"name" : "none",
"language" : "builtin"
},
"return_filter" : {
"body" : "position.endNode().getProperty('user_id')!=1 && position.endNode().getProperty('user_id')!=9 && position.endNode().getProperty('user_id')!=2 && position.endNode().getProperty('user_id')!=8 && position.endNode().getProperty('user_id')!=7 && position.endNode().getProperty('user_id')!=5;",
"language" : "javascript"
},
"relationships" : {
"direction" : "out",
"type" : "Friend"
},
"max_depth" : 3
}
Neo4jPHP Traversal[UPDATED]:
$traversal->addRelationship('Friend', Relationship::DirectionOut)
->setPruneEvaluator(Traversal::PruneNone)
->setReturnFilter('javascript', "position.endNode().getProperty('user_id')!=1 && position.endNode().getProperty('user_id')!=9 && position.endNode().getProperty('user_id')!=2 && position.endNode().getProperty('user_id')!=8 && position.endNode().getProperty('user_id')!=7 && position.endNode().getProperty('user_id')!=5;")
->setMaxDepth(3)
->setUniqueness(Traversal::UniquenessNodeGlobal)
->setOrder(Traversal::OrderBreadthFirst);
Using the Traversal Rest Api and Neo4jPHP Traversal above I got the result: 9,6,7,3,2,10,5,4,8
While the result I want is: 6,3,10,4
Because 9,7,2,5,8 are already friends with the user: 1
NOTE:
I just updated the way I traverse my graph to find friends of friends at depth of 3, so I updated my question too.
We can see that conditions I made in return_filter is manually:
"body" : "position.endNode().getProperty('user_id')!=1 && position.endNode().getProperty('user_id')!=9 && position.endNode().getProperty('user_id')!=2 && position.endNode().getProperty('user_id')!=8 && position.endNode().getProperty('user_id')!=7 && position.endNode().getProperty('user_id')!=5;"
While in Cypher, we can easily remove friends of friends that are already friends with user: 1:
WHERE NOT (U)-[:Friend]->(FFFU)
Now, how to make a condition like that in Traversal Rest Api?
I ask because not much info from the documentation.
Please anyone help me. I really need your help.
Thank you.
Shouldn't this be possible by simply specifying:
MATCH (user:User)-[:FRIEND*2..4]->(fof)
WHERE NOT (user)-[:FRIEND]->(fof)
Or perhaps I'm missing something, are you using the DISTINCT statements as a way to improve performance? I'm surprised cypher is not performing well for you here, would you be able to try your query with the PROFILE command in the Neo4j shell, and send me the result? You can email me at jakewins AT gmail.com
As for the traversal, conceptually, I would do this:
Start at User
Find all Users friends, and put them in a Set 'friends'
Start at each friend, and traverse out as many hops you like
Return each user found that is not in the set of friends
I don't believe you can do the set part in the REST traversal API, which means you either need to write a server extension, which will allow you to write this in Java and use the more powerful Java traversal API, you can read about extensions here: http://docs.neo4j.org/chunked/stable/server-unmanaged-extensions.html and the Java traversal API here: http://docs.neo4j.org/chunked/stable/tutorial-traversal-java-api.html
Alternatively, you can do two calls, one to fetch all the users friends, and one to do the REST traversal with the users friends as part of the script you send over, like you do in your question but with your app generating the filter code.

Count how many metrics matches a condition in graphite

I have a list of classes that extracts info from the web. Every time each one of them saves something, it sends a different counter to graphite. So, every one of them is a different metric.
How do I know how many of them satisfy a certain condition??
For example, let:
movingAverage(summarize(groupByNode(counters.crawlers.*.saved, 2, "sumSeries), "1hour"), 24)
be the average of content download in past 24 hours. How can i know, at a moment "t", how many of my metrics have this value above 0?
In the rendering endpoint, add format=json. This would return the data-points with corresponding epochs in JSON, which is a breeze to parse. The time-stamps wherein your script sent nothing will be NULL.
[{
"target": "carbon.agents.ip-10-0-0-228-a.metricsReceived",
"datapoints":
[
[912, 1383888170],
[789, 1383888180],
[800, 1383888190],
[null, 1383888200],
[503, 1383888210],
[899, 1383888220]
]
}]
You can use the currentAbove function. Check it out. For example:
currentAbove(stats.route.*.servertime.*, 5)
The above example gets all of the metrics (in the series) that are above 5.
You could then count the number of targets returned, and while Graphite doesn't provide a way to count the "buckets" you should be able to capture it fairly easily.
For example, a way to get a quick count (using curl to pipe to grep and count on the word "target"). Like so:
> curl -silent http://test.net/render?target=currentAbove(stats.cronica.dragnet.messages.*, 5)&format=json \
> | grep -Po "target" | grep -c "target"

Resources