Git Product home page Git Product logo

creative-screenshots's Introduction

Creative Screenshots

Please note: this is not an officially supported Google product.

This is a solution to render screenshots for placements from GMP Campaign Manager. It can take screenshots of an entire Campaign Manager Network. The application can be deployed on Google Cloud Run. It can be configured to generate n number of screenshots per placement.

Captured placements are stored in Datastore, so it can run daily without re-rendering already covered placements.

Supported tags: * Display * VAST

The application will run through the following steps:

  • List Advertisers: Lists all advertisers available to the Profile (User Account) this solution is using.
  • List Placements: Lists all placements per Advertiser
  • Generate Tags: Generates a JS or VAST tag for each placement found. VAST tags are unwrapped and only the media file is processed.
  • Render Screenshot: Loads the tag/media and takes n screenshots. Images are stored to Google Cloud Storage.

Setup

Cloud

Datastore

Enable Google Cloud Datastore Service:
$ gcloud services enable datastore.googleapis.com

Cloud Tasks

The application makes use of different task queues:

Queue Name Maximum Rate Maximum Concurrent
list-advertisers 1/s 1
list-placements 5/s 5
generate-tags 5/s 25
render-screenshot 5/s 40

To set up the queues as per above settings you can run the following commands:

Enable Google Cloud Tasks Service:
$ gcloud services enable cloudtasks.googleapis.com

Create Queues:
$ gcloud tasks queues create list-advertisers --max-dispatches-per-second=1 --max-concurrent-dispatches=1
$ gcloud tasks queues create list-placements --max-dispatches-per-second=5 --max-concurrent-dispatches=5
$ gcloud tasks queues create generate-tags --max-dispatches-per-second=5 --max-concurrent-dispatches=25
$ gcloud tasks queues create render-screenshot --max-dispatches-per-second=5 --max-concurrent-dispatches=40

Additional documentation on creating Google Cloud Task Queues.

Cloud Run

Enable Google Cloud Datastore Service:
$ gcloud services enable run.googleapis.com

Cloud Storage

Enable Google Cloud Storage Service:
$ gcloud services enable storage-component.googleapis.com

Cloud Bucket
Create a Google Cloud Bucket where all images will be stored.
$ gsutil mb gs://[BUCKET_NAME]/
Additional documentation on creating Google Cloud Buckets.

Service Account

Create a new IAM Service Account with the following roles:

  • Cloud Tasks Enqueuer
  • Cloud Datastore User
  • Storage Object Creator
  • Service Account User
  • Cloud Run Invoker
  • Storage Object Viewer

Enable Campgaign Manager API service:
$ gcloud services enable dfareporting.googleapis.com

Google Marketing Platform

Create a Campaign Manager User Profile with the service account's email address with the respective role: * Agency Trafficker

Use the service account's email address you are using for the Cloud Run service. By default this is the Compute Engine default service account.

Deploy

There's two ways to deploy this solution, directly from the built image on Google Cloud Container Registry or build and deploy from source.

By default, Cloud Run revisions are using the Compute Engine default service account ([email protected]). You can change this identity.
If you change it, make sure a Campaign Manager User Profile is created with this service account email address.

From GCR:

$ gcloud beta run deploy [SERVICE_NAME] \
--image gcr.io/creative-screenshots-external/creative-screenshot-service:stable \
--memory 2G \
--platform managed \
--service-account "[SERVICE_ACCOUNT_EMAIL]" \
--update-env-vars \
CLOUD_PROJECT_ID=$(gcloud config get-value project),\
CLOUD_RUN_REGION=us-central1,\
CLOUD_BUCKET=[CLOUD STORAGE BUCKET NAME],\
FILE_PATH_PATTERN="{accountId}/{advertiserId}/{campaignId}/{placementId}_{index}.jpg",\
SCREENSHOT_PADDING=16,\
SCREENSHOT_QUALITY=100,\
MS_BEFORE_SCREENSHOT=1000,\
MS_BEFORE_SCREENSHOT_INSTREAM=8000,\
NUMBER_OF_SCREENSHOTS=1

From Source:

To build the image use: $ npm run cloud-run-build
To deploy the built image: $ npm run cloud-run-deploy-only
To build and deploy: $ npm run cloud-run-deploy

Configuration

When deploying the application from NPM you can update the configuration in package.json under config, otherwise add it to the --update-env-vars of the gcloud deploy command.

Property Description Default Value
CLOUD_BUCKET Name of the Cloud Bucket all files are saved to. Files are saved in the structure defined by file path pattern. N/A
FILE_PATH_PATTERN All images are saved using this file pattern, bracketed values are replaced with actual ids. {accountId}/{advertiserId}/{campaignId}/{placementId}_{index}.jpg
SCREENSHOT_PADDING Total number of padding pixels around the screenshot, 16 results in 8 on each side. 16
SCREENSHOT_QUALITY JPG Quality setting. 100
MS_BEFORE_SCREENSHOT Milliseconds before taking a screenshot, this allows for a bit of the animation to start before taking a screenshot. This value is ignored if NUMBER_OF_SCREENSHOTS > 1. 1000
MS_BEFORE_SCREENSHOT_INSTREAM Milliseconds before taking a screenshot of a Video INSTREAM tag. This value is ignored if NUMBER_OF_SCREENSHOTS > 1. 8000
NUMBER_OF_SCREENSHOTS Number of screenshots to take for each placement. Display Ads will use a default of 15 second animation divided by NUMBER_OF_SCREENSHOTS. INSTREAM/VAST tags will use media duration divided by NUMBER_OF_SCREENSHOTS. Screenshot index can be captured in the file path by using {index}. 1

Run

For all Advertisers the service account has access to:
POST
https://SERVICE_ENDPOINT/list-advertisers

{
  "profileId": 000000
}

For a specific advertiser:
POST
https://SERVICE_ENDPOINT/list-placements

{
  "profileId": 000000,
  "advertiserId": 000000
}

creative-screenshots's People

Contributors

dependabot[bot] avatar halleyinteractive avatar jacob-l avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

creative-screenshots's Issues

HTTP instead of HTTPS on generated tasks

Hi there,
There seems to be a bit of an issue when I'm running this. Whenever one of the main functions (list-advertisers, list-placements, etc) creates its set of tasks in one of the task queues, it creates them as HTTP requests. However, only HTTPS requests seem to work under this solution.

Everything else works fine, so if I run the requests manually with Postman to the https:// address, they will work, but they don't propagate (i.e. I can send a list-placements job and it will list placements and create generate-tags jobs, but these won't actually do anything because they are address to the http:// address.

Any clues?

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.