Skip to content
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
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dbcredentials.txt
env
*.pyc
config.json
4 changes: 0 additions & 4 deletions config.json

This file was deleted.

26 changes: 26 additions & 0 deletions models/adwords/model.sql
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?
Copy link
Member

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"

)
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
)
11 changes: 11 additions & 0 deletions models/adwords/model_tests.sql
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

);
35 changes: 35 additions & 0 deletions models/facebook_ads/model.sql
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
)
11 changes: 11 additions & 0 deletions models/facebook_ads/model_tests.sql
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

);
51 changes: 51 additions & 0 deletions models/ppc/model.sql
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
)
)
)