This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #947 from solocommand/mindful-web-banner-ads
Mindful web banner ad delivery
- Loading branch information
Showing
20 changed files
with
242 additions
and
21 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
*.marko.js |
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,25 @@ | ||
{ | ||
"<marko-web-mindful-ads-website-banner>": { | ||
"template": "./website-banner.marko", | ||
"@ad-unit-id": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"@limit": { | ||
"type": "number", | ||
"default-value": 1 | ||
}, | ||
"@namespace": { | ||
"type": "string", | ||
"required": true | ||
}, | ||
"@sizes": { | ||
"type": "array", | ||
"default-value": [] | ||
}, | ||
"@debug": { | ||
"type": "boolean", | ||
"default-value": false | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/marko-web-mindful-ads/components/website-banner.marko
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,53 @@ | ||
import { randomElementId } from "@parameter1/base-cms-utils"; | ||
import { logger, fetchAds } from "../utils"; | ||
|
||
$ const { | ||
adUnitId, | ||
debug, | ||
sizes = [], | ||
limit = 1, | ||
namespace, | ||
} = input; | ||
$ const log = logger(debug); | ||
|
||
$ if (debug) log('website-banner-fetch input', input); | ||
$ const elementId = randomElementId({ prefix: 'mindful' }); | ||
|
||
<marko-web-resolve|{ resolved }| promise=fetchAds({ | ||
adUnitId, | ||
debug, | ||
sizes, | ||
limit, | ||
namespace, | ||
})> | ||
<if(resolved.error && process.env.NODE_ENV === 'development')> | ||
$ throw resolved.error; | ||
</if> | ||
$ /** @type {import("../utils/fetch-ads").MindfulWebsiteBannerCreative} **/ | ||
<for|creative| of=resolved.results> | ||
<div | ||
id=elementId | ||
data-unit-form="WEBSITE_BANNER" | ||
data-channel-id=resolved.unit.websiteChannel._id | ||
data-creative-id=creative._id | ||
data-unit-id=resolved.unit._id | ||
> | ||
<if(input.renderBody)> | ||
<${input.renderBody} unit=resolved.unit creative=creative /> | ||
</if> | ||
<else> | ||
<a href=creative.clickUrl target="_blank"> | ||
<img src=creative.src alt=creative.name /> | ||
</a> | ||
</else> | ||
</div> | ||
</for> | ||
<if(!resolved.results || !resolved.results.length)> | ||
<div | ||
id=elementId | ||
data-unit-form="WEBSITE_BANNER" | ||
data-channel-id=resolved.unit.websiteChannel._id | ||
data-unit-id=resolved.unit._id | ||
/> | ||
</if> | ||
</marko-web-resolve> |
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,6 @@ | ||
{ | ||
"taglib-id": "@parameter1/base-cms-marko-newsletters-mindful", | ||
"taglib-imports": [ | ||
"./components/marko.json" | ||
] | ||
} |
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,25 @@ | ||
{ | ||
"name": "@parameter1/base-cms-marko-web-mindful-ads", | ||
"version": "4.61.0", | ||
"description": "Mindful Ads Marko components for BaseCMS websites.", | ||
"author": "Josh Worden <[email protected]>", | ||
"license": "MIT", | ||
"repository": "https://github.com/parameter1/base-cms/tree/master/packages/marko-web-mindful-ads", | ||
"scripts": { | ||
"lint:fix": "yarn lint --fix", | ||
"lint": "eslint --ext .js --max-warnings 5 ./", | ||
"compile": "basecms-marko-compile compile", | ||
"prepublish": "yarn compile --silent", | ||
"test": "yarn compile --no-clean && yarn lint" | ||
}, | ||
"dependencies": { | ||
"@parameter1/base-cms-utils": "^4.40.3", | ||
"node-fetch": "^2.6.9" | ||
}, | ||
"peerDependencies": { | ||
"@parameter1/base-cms-marko-core": "^4.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,83 @@ | ||
const fetch = require('node-fetch'); | ||
const logger = require('./logger'); | ||
|
||
const { error } = console; | ||
const host = process.env.MINDFUL_ADVERTISING_DELIVERY_API_URL || 'https://delivery.mindfulcms.com'; | ||
|
||
/** | ||
* @param MindfulWebsiteBannerRequestArgs | ||
* @returns {Promise<MindfulWebsiteBannerResponse[]>} | ||
*/ | ||
module.exports = async ({ | ||
adUnitId, | ||
debug = true, | ||
limit = 1, | ||
sizes = [], | ||
namespace, | ||
} = {}) => { | ||
if (!namespace) throw new Error('Mindful namespace must be supplied.'); | ||
if (!adUnitId) throw new Error('Mindful ad unit id must be supplied.'); | ||
const log = logger(debug); | ||
log({ | ||
adUnitId, | ||
limit, | ||
sizes, | ||
namespace, | ||
}); | ||
try { | ||
const url = new URL(`${host}/${namespace}/website-banner/${adUnitId}`); | ||
url.searchParams.set('limit', limit); | ||
sizes.forEach((size) => url.searchParams.append('sizes', size)); | ||
const res = await fetch(url); | ||
if (!res.ok) throw new Error(`Unable to retrieve mindful ads: ${res.status} ${res.statusText}`); | ||
return res.json(); | ||
} catch (e) { | ||
error('Unable to retrieve mindful ads!', e); | ||
return { error: e }; | ||
} | ||
}; | ||
|
||
/** | ||
* @typedef MindfulWebsiteBannerRequestArgs | ||
* @prop {string} namespace The Mindful namespace (tenant/workspace keys) | ||
* @prop {string} adUnitId | ||
* @prop {boolean} debug | ||
* @prop {string[]} sizes | ||
* | ||
* @typedef MindfulWebsiteBannerAdUnit | ||
* @prop {string} _id | ||
* @prop {string[]} sizes | ||
* @prop {string} name | ||
* @prop {MindfulWebsiteChannel} websiteChannel | ||
* | ||
* @typedef MindfulWebsiteChannel | ||
* @prop {string} _id | ||
* @prop {string} name | ||
* | ||
* @typedef MindfulAdvertisingOrder | ||
* @prop {string} _id | ||
* @prop {string} name | ||
* | ||
* @typedef MindfulAdvertisingCompany | ||
* @prop {string} _id | ||
* @prop {string} name | ||
* | ||
* @typedef MindfulWebsiteBannerCreative | ||
* @prop {string} _id | ||
* @prop {string} form | ||
* @prop {string} kind | ||
* @prop {number} width | ||
* @prop {number} height | ||
* @prop {string} clickUrl | ||
* @prop {string} src | ||
* @prop {MindfulWebsiteBannerLineItem} lineItem | ||
* @prop {MindfulAdvertisingOrder} order | ||
* @prop {MindfulAdvertisingCompany} company | ||
* | ||
* @typedef MindfulWebsiteBannerResponse | ||
* @prop {MindfulWebsiteBannerAdUnit} unit | ||
* @prop {number} limit | ||
* @prop {string[]} sizes | ||
* @prop {MindfulWebsiteBannerCreative[]} results | ||
* | ||
*/ |
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,7 @@ | ||
const fetchAds = require('./fetch-ads'); | ||
const logger = require('./logger'); | ||
|
||
module.exports = { | ||
fetchAds, | ||
logger, | ||
}; |
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,5 @@ | ||
const { log } = console; | ||
|
||
module.exports = (debug = false, key = 'mindful') => (...args) => { | ||
if (debug) log(key, ...args); | ||
}; |
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
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/bash | ||
docker-compose down | ||
docker compose down |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
docker compose run \ | ||
--rm \ | ||
--no-deps \ | ||
--entrypoint yarn \ | ||
|
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
docker compose run \ | ||
--rm \ | ||
--no-deps \ | ||
--entrypoint /bin/bash \ | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
docker compose run \ | ||
--rm \ | ||
--no-deps \ | ||
--entrypoint yarn \ | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
docker compose run \ | ||
--rm \ | ||
--no-deps \ | ||
--entrypoint yarn \ | ||
|
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
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
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