-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PPC Analysis #16
base: master
Are you sure you want to change the base?
PPC Analysis #16
Changes from 7 commits
65a35cd
f19c58b
364eade
28b2529
c0eb8ad
8f505b4
9d63988
07a2a83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
dbcredentials.txt | ||
env | ||
*.pyc | ||
config.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
create or replace view {schema}.ppc_consolidated_summary as ( | ||
( | ||
select | ||
* | ||
from | ||
( | ||
select | ||
'Google' as "@adnetwork", | ||
"@campaign_name", | ||
"@utm_source", | ||
"@utm_medium", | ||
"@utm_campaign", | ||
"@utm_content", | ||
"@utm_term", | ||
"@impressions"::integer, | ||
"@cost"::float, | ||
"@date"::date, | ||
"@clicks"::integer, | ||
"@base_url" | ||
from | ||
{schema}.adwords_summary | ||
) | ||
) | ||
-- union if other adnetworks present. can we make this happen automatically? | ||
union all | ||
( | ||
select | ||
* | ||
from | ||
( | ||
select | ||
'Facebook' as "@adnetwork", | ||
"@campaign_name", | ||
"@utm_source", | ||
"@utm_medium", | ||
"@utm_campaign", | ||
"@utm_content", | ||
"@utm_term", | ||
"@impressions"::integer, | ||
"@cost"::float, | ||
"@date"::date, | ||
"@clicks"::integer, | ||
"@base_url" | ||
from | ||
{schema}.facebook_summary | ||
) | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
######################################## | ||
# PPC Interface # | ||
######################################## | ||
|
||
adnetwork varchar | ||
campaign_name varchar | ||
utm_source varchar | ||
utm_medium varchar | ||
utm_campaign varchar | ||
utm_content varchar | ||
utm_term varchar | ||
impressions integer | ||
cost float | ||
clicks integer | ||
date date | ||
base_url varchar |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
create or replace view {schema}.adwords_summary as ( | ||
with ad_data as | ||
( | ||
select | ||
lower(addestinationurl) as cleanurl, | ||
* | ||
from | ||
adwords.adwords12218869_v2 -- How do I make this work regardless of the extension? | ||
) | ||
select | ||
REPLACE(REGEXP_SUBSTR(cleanurl,'utm_source=[^&]*'),'utm_source=','') as "@utm_source", | ||
REPLACE(REGEXP_SUBSTR(cleanurl,'utm_medium=[^&]*'),'utm_medium=','') as "@utm_medium", | ||
REPLACE(REGEXP_SUBSTR(cleanurl,'utm_campaign=[^&]*'),'utm_campaign=','') as "@utm_campaign", | ||
REPLACE(REGEXP_SUBSTR(cleanurl,'utm_content=[^&]*'),'utm_content=','') as "@utm_content", | ||
REPLACE(REGEXP_SUBSTR(cleanurl,'utm_term=[^&]*'),'utm_term=','') as "@utm_term", | ||
campaign as "@campaign_name" | ||
impressions::integer as "@impressions", | ||
adcost::float as "@cost", | ||
date::date as "@date", | ||
adclicks::integer as "@clicks", | ||
SPLIT_PART(cleanurl,'?',1) as "@base_url", | ||
SPLIT_PART(cleanurl,'?',2) as querystring, | ||
* | ||
from | ||
ad_data | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create or replace view {schema}.model_tests | ||
(name, description, result) | ||
as ( | ||
|
||
select | ||
'adwords_fresher_than_one_day', | ||
'Most recent adwords entry is no more than one day old', | ||
max("@date"::date) > current_date - '1 day'::interval | ||
from {schema}.adwords_summary | ||
|
||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
create or replace view ac_hhund.facebook_ads_summary as ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace ac_hhund with {schema} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
with ad_data as | ||
( | ||
select | ||
ag.name as "adgroup_name", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why quotes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
lower(nvl(object_url,link_url,object_story_spec__link_data__link)) as addestinationurl, | ||
i.* | ||
from | ||
facebook.facebook_insights_101441173373823 i | ||
join | ||
facebook.facebook_adgroup_101441173373823 ag | ||
on | ||
ag.id = i.adgroup_id | ||
join | ||
facebook.facebook_adcreative_101441173373823 ac | ||
on | ||
ag.creative__id = ac.id | ||
) | ||
select | ||
REPLACE(REGEXP_SUBSTR(addestinationurl,'utm_source=[^&]*'),'utm_source=','') as "@utm_source", | ||
REPLACE(REGEXP_SUBSTR(addestinationurl,'utm_medium=[^&]*'),'utm_medium=','') as "@utm_medium", | ||
REPLACE(REGEXP_SUBSTR(addestinationurl,'utm_campaign=[^&]*'),'utm_campaign=','') as "@utm_campaign", | ||
REPLACE(REGEXP_SUBSTR(addestinationurl,'utm_content=[^&]*'),'utm_content=','') as "@utm_content", | ||
REPLACE(REGEXP_SUBSTR(addestinationurl,'utm_term=[^&]*'),'utm_term=','') as "@utm_term", | ||
adgroup_name as "@campaign_name", | ||
impressions::integer as "@impressions", | ||
spend::float as "@cost", | ||
date_start::date as "@date", | ||
clicks::integer as "@clicks", | ||
SPLIT_PART(addestinationurl,'?',1) as "@base_url", | ||
SPLIT_PART(addestinationurl,'?',2) as querystring, | ||
* | ||
from | ||
ad_data | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create or replace view {schema}.model_tests | ||
(name, description, result) | ||
as ( | ||
|
||
select | ||
'facebook_ads_fresher_than_one_day', | ||
'Most recent facebook ads entry is no more than one day old', | ||
max("@date"::date) > current_date - '1 day'::interval | ||
from {schema}.facebook_ads_summary | ||
|
||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chris worked on a solution to this problem here: #8
Ideally, it would look like
adwords.adwords{adwords_id}
(or something) and the{adwords_id}
would be interpolated by the runner at "compile time"