forked from gitcoinco/code_fund_ads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmicroftech65 code_fund_ads_sponsorship
More file actions
251 lines (126 loc) · 8.4 KB
/
microftech65 code_fund_ads_sponsorship
File metadata and controls
251 lines (126 loc) · 8.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
microftech65/code_fund_ads
forked from gitcoinco/code_fund_adsCodeFund is an open source platform that helps fund maintainers, bloggers, and builders through non-tracking ethical ads https://codefund.io
AGPL-3.0 License
RubyHTMLJavaScriptTSQLCSSShell
Commit time.circleciAd demo page (gitcoinco#963)GitHub update issue templates and add PR template (gitcoinco#807)
appfix user relationship on organization model (gitcoinco#1008) Update to use METABASE
docs/diagramsUpdate advertiser kit, add Organization images (gitcoinco#975)
Retrieved:
CodeFund Ads
CodeFund Ads is an ethical and discreet ad platform that funds open-source. It helps your favorite projects thrive by paying maintainers the majority of all generated revenue.
Publishing & JavaScript CodeFund script Code Fund div. <div id="codefund"></div> <script src="https://codefund.app/properties/PROPERTY_ID/funder.js" async="async" type="text/javascript"></script>
Optional Query String Parameters
template - the template to use overrides the property config
theme - the theme to use overrides the property config
keywords - the keywords to use for targeting (comma delimited string) overrides the property config
Setting async on the script tag will ensure that CodeFund doens't block anything on the publisher's site.
Embed Callbacks
You may want to perform a function if the embed function does not return an ad.
To do this, you must create an event listener for the window event codefund.
Demo:
window.addEventListener("codefund", function(evt) { if (evt.detail.status !== 'ok') { // Do something else console.log(evt.detail.status); } });
On a successful embed, evt.detail will return:
{ "status": "ok", "house": false } or { "status": "ok", "house": true } // Ad returned is a house ad
If an error occurs with embedding the ad, evt.detail will return:
{ "status": "error", "message": "error message" }
And in the event that we do not have an available advertiser, you will see:
{ "status": "no-advertiser" }
API
The API is documented with Blueprint and is hosted on Apiary.
NOTE: Apairy doesn't fully adhere to the Blueprint 1A9 specification. Our Blueprint file may deviate from the spec to satisfy Apiary limitations.
https://github.com/gitcoinco/code_fund_ads/blob/master/BLUEPRINT.md
Ad Rendering and Impression/Click Tracking
The URLs/routes responsible for ad rendering are:
GET /properties/1/funder.js → advertisements#show - embed script
This is the embed JavaScript that publishers place on their site. It includes the ad HTML and some logic to inject the HTML to the page and setup the links and impression pixel.
GET /scripts/76bfe997-898a-418c-8f0b-6298b7dd320a/embed.js → advertisements#show - embed script
This endpoint is to support our legacy system (CodeFund v1) embed URLs. It points to the same endpoint as /properties/1/funder.js.
GET /display/76bfe997-898a-418c-8f0b-6298b7dd320a.gif → impressions#show - creates an impression
This is the impression pixel image. The impression is created after this image is requested and served successfully. This means that a matching campaign was found and the embed JavaScript did its job correctly.
GET /impressions/76bfe997-898a-418c-8f0b-6298b7dd320a/click?campaign_id=1 → advertisement_clicks#show - creates a click
This is the proxy/redirect URL that allows us to track the click. We immediately redirect to the advertiser's campaign URL and background the work to mark the associated impression as clicked.
Enums
All enum values are managed as constants defined in config/enums.yml This file is converted to Ruby constants at runtime.
Introspect what enums are defined via the cli.
ENUMS.constants ENUMS::USER_ROLES.constants # etc...
Always use enums instead of "magic" values.
Development Environment
Prerequisites
Ruby version 2.6.5
rbenv
asdf
NodeJS version 13.0.1
nvm
asdf
Bundler version 2.1.1
gem install bundler
Yarn
Mac: instructions
Ubuntu: instructions
graphviz
Mac: brew install graphviz
Ubuntu: sudo apt-get install graphviz
PostgreSQL 11
Mac: instructions
Ubuntu: instructions
Redis
Mac: brew install redis && brew services start redis
Ubuntu: instructions
You must create a (superuser) role with the name of your OS user in your postgres configuration in order to run db operations (e.g. testing and development).
git clone https://github.com/gitcoinco/code_fund_ads.git cd /path/to/project # setup environment variables cp .env-example .env # If you need a password for your postgres role, uncomment "#export PGPASSWORD='<password>' in the .env file and replace <password> with the role's password # install dependencies bundle install yarn install # db setup + tests rails db:create db:migrate rails test # start app and navigate to http://localhost:3000 rails s
It is recommended to develop with Rails cache enabled. This application relies heavily on caching and may not work properly without the cache enabled.
bundle exec rails dev:cache # => Development mode is now being cached.
Database Seeds
The impressions table will seed with approximately 100k records spread over 12 months by default. You can increase this by setting the IMPRESSIONS environment variable and seeding again.
IMPRESSIONS=10_000_000 rails db:seed
Tmux/Teamocil or Mert
You may want to create a teamocil/tmux config for your machine.
SEE: https://github.com/gitcoinco/code_fund_ads/blob/master/.teamocil-example.yml
cd /path/to/project ./bin/teamocil
Alternatively, you may want to create a mert config for your machine to be used with iTerm.
SEE: https://github.com/gitcoinco/code_fund_ads/blob/master/.mert-example.yml
cd /path/to/project ./bin/mert
Code Standards
We avoid bike shedding by enforcing coding standards through tooling.
Ruby - standard
JavaScript - prettier-standard
Ensure the code has been standardized by running the following before you commit.
./bin/standardize
Deployment
All pushes of master to Github result in a deployment to the staging environment. We use Herou build pipelines to promote the deployment to environments like production.
./bin/heroku_promote
Preboot
The application is configured for zero downtime deployments using Heroku's preboot feature.
This means that 2 versions of the application will be running simultaneously during deploys. All code changes should consider this deployment requirement to ensure that both versions of the app are valid and can run in parallel.
If breaking changes are unavoidable, disable preboot prior to deployment.
./bin/heroku_preboot_disable ./bin/heroku_promote ./bin/heroku_preboot_enable
Scheduler
There are several tasks that should be scheduled to run at different intervals. We manage this with Heroku Scheduler.
rails schedule:counter_updates - hourly
rails schedule:update_campaign_statuses - daily
Database
The impressions table is dynamically partitioned by advertiser (i.e. user) and date
The database user requires permissions to execute DDL and create schema to support dynamic partition tables
Maxmind
This product includes GeoLite data created by MaxMind, available from: http://www.maxmind.com
The GeoLite2-City.tar.gz is checked into this repo at db/maxmind/GeoLite2-City.tar.gz
A fresh copy of the GeoLite2-City.tar.gz file can be obtained by running one of the following commands.
rails maxmind:download
DownloadAndExtractMaxmindFileJob.new.download
Instrumentation
CodeFund uses a self-hosted version of count.ly to gather and analyze data. This data does not include any personal identifiable information.
The pattern in which to instrument CodeFund with is as follows:
CodeFundAds::Events.track(:action, :device_id, :segmentation)
Each variable can be the following value:
action - the label for the action being tracked (e.g. find_virtual_impression)
device_id - the session or unique ID of the visit
segmentation - hash of key value pairs that can be used to segment the data
The segmentation typically includes:
status - the status of the action (e.g. success or fail)
ip_address - the IP address of the visitor
property_id - the Property ID
campaign_id - the Campaign ID
creative_id - the Creative ID
country_code - the country code
Demo:
# Application & Environment are added by default CodeFundAds::Events.track("Find Virtual Impression", session.id, { status: "fail", ip_address: "127.0.0.1" }) CodeFundAds::Events.track("Find Fallback Campaign", session.id, { status: "success", ip_address: "127.0.0.1", property_id: 1, country_code: "US" })