Skip to content

Commit 65648e5

Browse files
committed
Naked Wines
1 parent 2363c47 commit 65648e5

File tree

15 files changed

+106
-6
lines changed

15 files changed

+106
-6
lines changed

component/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const sectionStyle = {
55
backgroundPosition: 'center',
66
backgroundSize: 'cover',
77
backgroundRepeat: 'no-repeat',
8-
height: '195px'
8+
height: '900px'
99
};
1010

1111

pages/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const dataFileUrl = `https://cdn.optimizely.com/datafiles/${sdkKey}.json`;
1717
export default function Home({...props}) {
1818

1919
const [ isFeatureEnabled, renderIsFeatureEnabled ] = useState(true);
20-
const [ backgroundColor, setBackgroundColor ] = useState('');
20+
const [ backgroundColour, setBackgroundColor ] = useState('');
2121
const [ componentTitle, setComponentTitle ] = useState('');
2222
const [ postData, setPostData ] = useState({});
2323

@@ -29,7 +29,7 @@ export default function Home({...props}) {
2929
});
3030

3131
// Got user Id either via query-string, or, create a random one
32-
const { id, location } = router.query
32+
const { id } = router.query
3333
const userId = id || uuidv4();
3434

3535
let optimizelyUserContext;
@@ -38,7 +38,7 @@ export default function Home({...props}) {
3838
optimizelyUserContext = optimizelyClient.createUserContext(
3939
userId,
4040
{
41-
location: location || "london",
41+
location: "london",
4242
deviceType: "ios"
4343
}
4444
);
@@ -55,7 +55,7 @@ export default function Home({...props}) {
5555

5656
// AB Testing Code
5757
const abTestData = optimizelyUserContext.decide('ab_test');
58-
setBackgroundColor(abTestData.variables.backgroundcolour);
58+
setBackgroundColor(abTestData.variables.backgroundColour);
5959
setComponentTitle(abTestData.variables.component_title);
6060

6161
/// Multi-arm bandit code
@@ -117,7 +117,7 @@ export default function Home({...props}) {
117117
</h2>
118118
</header>
119119

120-
<ABComponent userId={userId} optimizelyClient backgroundColor={backgroundColor} componentTitle={componentTitle} />
120+
<ABComponent userId={userId} optimizelyClient backgroundColor={backgroundColour} componentTitle={componentTitle} />
121121

122122
</div>
123123
<div className="container">

pages/landing.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import Head from 'next/head'
2+
import React, { useEffect, useState } from "react";
3+
import { v4 as uuidv4 } from 'uuid';
4+
5+
import { useRouter } from 'next/router'
6+
7+
import {
8+
createInstance
9+
} from "@optimizely/optimizely-sdk";
10+
11+
const sdkKey = process.env.NEXT_PUBLIC_SDK_KEY;
12+
const dataFileUrl = `https://cdn.optimizely.com/datafiles/${sdkKey}.json`;
13+
14+
export default function Landing({...props}) {
15+
16+
const [ displayBanner, renderPersonalisationBanner ] = useState(false);
17+
18+
const router = useRouter()
19+
20+
const optimizelyClient = createInstance({
21+
datafile: props?.datafile,
22+
});
23+
24+
const { user = '' } = router.query
25+
const userId = uuidv4();
26+
27+
let optimizelyUserContext;
28+
29+
console.log('user segment', user);
30+
31+
optimizelyClient.onReady().then(() => {
32+
optimizelyUserContext = optimizelyClient.createUserContext(
33+
userId,
34+
{
35+
user: user
36+
}
37+
);
38+
});
39+
40+
useEffect(() => {
41+
optimizelyClient.onReady().then(() => {
42+
43+
const decision = optimizelyUserContext.decide('personalisation');
44+
console.log('matched on key', decision.ruleKey, decision);
45+
46+
renderPersonalisationBanner(decision.enabled);
47+
});
48+
}, [optimizelyUserContext, optimizelyClient]);
49+
50+
return (
51+
<>
52+
<Head>
53+
54+
<title>
55+
Optimizely Fullstack Javascript
56+
</title>
57+
58+
<meta name="description" content="Generated by JonDJones" />
59+
<link rel="icon" href="/favicon.ico" />
60+
</Head>
61+
62+
<section id="features">
63+
<div className="container" id="feature-container">
64+
<header>
65+
<h2>
66+
<strong>
67+
{"Display Personlisation: " + displayBanner}
68+
</strong>
69+
</h2>
70+
</header>
71+
</div>
72+
</section>
73+
74+
{displayBanner ?
75+
<section id="main">
76+
<div className="container">
77+
<header>
78+
<h2>
79+
<strong>
80+
Hello VIP User!
81+
</strong>
82+
</h2>
83+
</header>
84+
</div>
85+
</section> : null
86+
}
87+
</>
88+
)
89+
}
90+
91+
export async function getServerSideProps(context) {
92+
const response = await fetch(dataFileUrl);
93+
const datafile = await response.json();
94+
95+
return {
96+
props: {
97+
datafile
98+
}
99+
}
100+
}

public/demo/banner-1.gif

3.21 MB
Loading

public/demo/banner-2.gif

2.5 MB
Loading

public/demo/banner.gif

7.57 MB
Loading

public/images/1.png

-1.24 MB
Loading

public/images/2.png

-480 KB
Loading

public/images/3.png

294 KB
Loading

public/images/alt-body.png

-1.32 MB
Binary file not shown.

0 commit comments

Comments
 (0)