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

feat: target integration using json offers #448

Closed
wants to merge 22 commits into from
Closed
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
6 changes: 6 additions & 0 deletions solutions/blocks/hero/hero.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ main .hero-container .hero-wrapper {
padding: 0;
}

.two .hero-awards{
border: red 10px solid;
display: flex;
flex-direction: column;
}

main .hero {
position: relative;
padding: 0;
Expand Down
48 changes: 47 additions & 1 deletion solutions/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,61 @@
['x-default', { baseUrl: 'https://www.bitdefender.com', pageType: '.html' }],
];

const targetPromise = (async () => {
const targetLocation = getMetadata('experiment-target-location');
console.log(`Resolving target audience for location: ${targetLocation}`);

Check warning on line 56 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

Check warning on line 56 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement
const randomString = Math.random().toString(36).substring(7);
const resp = await fetch(`https://sitesinternal.tt.omtrdc.net/rest/v1/delivery?client=sitesinternal&sessionId=${randomString}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
context: {
channel: 'web',
},
execute: {
pageLoad: {},
mboxes: [
{
name: targetLocation,
index: 0,
},
],
},
}),
});
const payload = await resp.json();
console.log(`Received payload: ${JSON.stringify(payload)}`);

Check warning on line 79 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

Check warning on line 79 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement
const mbox = payload.execute.mboxes.find((mbox) => mbox.name === targetLocation);

Check failure on line 80 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

'mbox' is already declared in the upper scope on line 80 column 9

Check failure on line 80 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

'mbox' is already declared in the upper scope on line 80 column 9
console.log(`Received target offer: ${mbox?.options[0].content}`);

Check warning on line 81 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

Check warning on line 81 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement
const { url } = mbox?.options[0].content ?? { url: null };
console.log(`Resolved challenger url: ${url}`);

Check warning on line 83 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

Check warning on line 83 in solutions/scripts/scripts.js

View workflow job for this annotation

GitHub Actions / linting

Unexpected console statement

if (url) {
// Add the current audience to the page
const link = document.createElement('meta');
link.setAttribute('property', 'audience:current');
link.content = url;
document.getElementsByTagName('head')[0].appendChild(link);
}

return !!url;
})();

const AUDIENCES = {
current: () => targetPromise.then(() => true),
};

window.hlx.plugins.add('rum-conversion', {
load: 'lazy',
url: '../plugins/rum-conversion/src/index.js',
});

window.hlx.plugins.add('experimentation', {
condition: () => getMetadata('experiment'),
options: {
prodHost: 'www.bitdefender.com.au',
audiences: AUDIENCES,
},
url: '../plugins/experimentation/src/index.js',
});
Expand Down
14 changes: 14 additions & 0 deletions target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
curl -vvv -X POST -H "Content-type: application/json" -d '{
"context": {
"channel": "web"
},
"execute": {
"pageLoad": {},
"mboxes": [
{
"name": "Experiment 1",
"index": 0
}
]
}
}' 'https://sitesinternal.tt.omtrdc.net/rest/v1/delivery?client=sitesinternal&sessionId=9'
Loading