Giter Site home page Giter Site logo

gitcoinco / code_fund_ads Goto Github PK

View Code? Open in Web Editor NEW
373.0 22.0 107.0 230.38 MB

CodeFund is an open source platform that helps fund maintainers, bloggers, and builders through non-tracking ethical ads

Home Page: https://codefund.io

License: GNU Affero General Public License v3.0

Ruby 60.62% JavaScript 8.13% CSS 3.23% HTML 21.89% Shell 0.21% TSQL 5.80% Dockerfile 0.12%
open-source sustainability codefund advertising ethics ruby ruby-on-rails

code_fund_ads's Introduction

Maintainability All Contributors StackShare Join the conversation FOSSA Status codecov TODOs

CircleCI ERB Lint StandardRB Prettier-Standard


Logo

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.

Table of Contents

Publisher JavaScript Embedding

After being approved on the CodeFund platform, publishers can add CodeFund ads to their site by including the CodeFund script and adding the CodeFund div.

<div id="codefund"></div>
<script src="https://codefund.app/properties/PROPERTY_ID/funder.js" async></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.

Example

window.addEventListener("codefund", function(evt) {
  if (evt.detail.status !== 'ok') {
    console.log(evt.detail.status);
    // Do something
  }
});

Responses

On a successful embed, evt.detail will return:

{ "status": "ok", "house": false }

// or

{ "status": "ok", "house": true } // Ad returned is a house (fallback) ad

If an error occurs with embedding the ad, evt.detail will return:

{ "status": "error", "message": "error message" }

In the event that we do not have an available advertiser, and thus no available (paid or fallback) ad, evt.detail will return:

{ "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.

The online version is generated from this file.

Ad Rendering and Impression/Click Tracking

The URLs/routes responsible for ad rendering are:

  • GET /properties/1/funder.jsadvertisements#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.jsadvertisements#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.gifimpressions#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=1advertisement_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.

Development

If you'd like to use Docker to run the app, view that documentation here.

The following is for setting the app up on your local machine:

Prerequisites

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).

Setup

# clone the repo & cd into the project
git clone https://github.com/gitcoinco/code_fund_ads.git
cd /path/to/code_fund_ads

# 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

# enable development caching
rails dev:cache

# start app and navigate to http://localhost:3000
rails s

Development Caching

This application relies heavily on caching and will not work properly without the development cache enabled.

bundle exec rails dev:cache # => Development mode is now being cached.

Database

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

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

Workspace Setup

We provide a few example files for some popular tools to help you get up an running.

SEE: sample config file

cd /path/to/code_fund_ads
./bin/tmuxinator

SEE: sample config file

cd /path/to/code_fund_ads
./bin/teamocil

SEE: sample config file

cd /path/to/code_fund_ads
./bin/mert

Code Standards

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.

Linting

We avoid bike shedding by enforcing coding standards through tooling.

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

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

Example:

# 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"
})

Candidates for GEM extraction

  • Searchable ActiveStorage metadata
  • Eventable

Contributors

Thanks goes to these wonderful people (emoji key):


Nathan Hopkins

💻 📖 🤔 🚇 📦 🔌 📆 👀 ⚠️ 🔧

Eric Berry

💻 🎨 📖 🤔 🚇 📦 📆 👀 ⚠️

Ron Cooke

💻 📖

Mike

📖

Arun Kumar

💻 📖

Maxim Dzhuliy

📖

Andrew Mason

💻 🎨 📖 🚇 👀 ⚠️ 🔧

Matt Glaman

💻 ⚠️

Aditya Anand M C

📖

dcd018

💻

Puru Dahal

💻

Curtis Mckee

⚠️ 💻 🎨

jeremiG

📖

Kashif Rafique

💻

Ethan

📖

XhmikosR

💻

Jason Barnabe

💻

Руслан Корнев

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

AGPL-3.0

FOSSA Status

code_fund_ads's People

Contributors

allcontributors[bot] avatar andrewmcodes avatar arku avatar barbeque avatar booligoosh avatar brascoder avatar curtismckee avatar dahal avatar dependabot[bot] avatar fossabot avatar hopsoft avatar jasonbarnabe avatar logichub avatar max-si-m avatar mglaman avatar thelostone-mc avatar tpscrpt avatar woto avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code_fund_ads's Issues

Creatives CRUD

User Story

As an administrator or advertiser, I want to view, create, update, and delete creatives so that I can manage the ad creatives for campaigns.

Add style to devise emails using inky

When an email is delivered from devise, the email must utilize a common themed layout (using inky)

Acceptance Critera

  • Confirmation Instructions
  • Email Changed
  • Invitation Instructions (html)
  • Invitation Instructions (text)
  • Password Change
  • Reset Password Instructions
  • Unlock Instructions

Support legacy URL's for publishers

Old URLs:

  • Pixel: /p/:impression_id/pixel.png
  • Click: /c/:impression_id
  • Embed: /scripts/:property_id/embed.js
  • Details: /t/s/:property_id/details.json
  • API track impression: /api/v1/impression/:property_id

Note that only the Embed script must work.

Honor property keywords in query string for ad targeting

User Story

As a publisher, I want to pass keywords on the query string so that I can support different keywords to target different sections of my website.

Description

Order of precedence for property keywords should be:

  1. Query String
  2. Property Configuration

Remaining for MVP

What's Left

General

Applicants (Not MVP)

Dashboard

Properties

  • Property card needs to show real stats (@hopsoft)

Campaigns

  • Update stats on dashboard (@hopsoft)
  • #100 Details needs to show "refresh screenshot" button (admin only) (@coderberry)
  • Budgets need to show data for dates (likely paginated) (@hopsoft)
  • Nate might add ___ gem on budget tab (@hopsoft)
  • #103 Properties tab UI love (@coderberry)
  • Properties tab needs stats (nate) (@hopsoft)
  • #102 Remove "advertiser" from table when logged in as advertiser (@coderberry)
  • Add remaining budget to table (@hopsoft)
  • Add CTR to table (@hopsoft)

Properties

  • Dashboard needs data (@hopsoft)
  • #103 Embed instructions needs love (or seperate tab) (@coderberry)
  • #97 Earnings (THIS IS BIG) (@hopsoft)
  • Campaigns table might need Nate love (@hopsoft)
  • Distributions doesn't exist (@hopsoft)
  • #102 Remove "publisher" from table when logged in as publisher (@coderberry)
  • Add earnings to table (@hopsoft)
  • Add CTR to table (@hopsoft)
  • Allow editing of ad_template, ad_theme, prohibited_advertiser_ids, prohibit_fallback_campaigns, revenue_percentage (@coderberry)

Creatives

  • Stats on creative cards (@hopsoft)
  • Missing show page for creative. This will show all templates and stats for this creative. (@coderberry)
  • Add "We are working on this" note on show page (@coderberry)

Images

  • Unable to upload images on stage/prod (@coderberry)
  • Allow images to appear direct from cdn2.codefund.app (cloudfront) (@hopsoft)

Inbound Funds

Distributions

Expand data seed strategy

User Story

As a developer, I want to quickly seed my local database so that I can work with realistic data.

Description

Data seeds should produce the following data:

  • 100 Advertisers
  • 1000 Publishers
  • 100 * 1-10 Campaigns
  • 1000 * 1-10 Properties
  • 1000 [default] Impressions with the option to create up to 30M

Acceptance Criteria

Developers can run the following command to seed the data defaults listed above.

rails db:seed

Developers can run the following command to seed data defaults plus 30M impression records.

MAX_IMPRESSIONS=30_000_000 rails db:seed

Running seeds should be idempotent. i.e. Running rails db:seed twice will not create 200 Advertisers.

Add audit tracking for models

User Story

As ad administrator, I can see up to 20 of the most recent changes for models.

  • Creatives
  • Properties
  • Campaigns
  • Users

Update Ad Templates to work with new structure

The default template at app/views/ad_templates/default/index.html.erb and the theme at app/views/ad_templates/default/themes/light.css have been configured to work with the new rendering strategy.

All remaining ad templates (and themes) under app/views/ad_templates need to be updated to work with the new rendering strategy in a similar fashion.

Notable changes are:

  • #cf_ad has been replaced by #cf
  • caching by @campaign
  • server side rendering using @campaign.creative
  • images and urls have been updated for server side rendering

Note that all themes should have both light and dark stylesheets. If one doesn't exist, it should be stubbed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.