-
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
Open
henryhund
wants to merge
8
commits into
analyst-collective:master
Choose a base branch
from
henryhund:ppc-analysis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PPC Analysis #16
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
65a35cd
starting ppc analysis
henryhund f19c58b
define adwords_summary schema
henryhund 364eade
added adwords model test and started ppc analysis
henryhund 28b2529
added interface for ppc
henryhund c0eb8ad
added campaign_name
henryhund 8f505b4
updated interface
henryhund 9d63988
added facebook model and incorporated into ppc summary
henryhund 07a2a83
fixed pull request notes. refactored ppc analysis to be a model
henryhund File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
dbcredentials.txt | ||
env | ||
*.pyc | ||
config.json |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
create or replace view {schema}.facebook_ads_summary as ( | ||
with ad_data as | ||
( | ||
select | ||
ag.name as adgroup_name, | ||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
-- assuming there is google adwords and facebook ads. | ||
-- need to make this flexible such that we can detect any relevant paid ad platforms and union them in. | ||
|
||
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 | ||
) | ||
) | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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"