Skip to content
Snippets Groups Projects
Commit 70ca27cf authored by Rebecca Pösche Ruud's avatar Rebecca Pösche Ruud
Browse files

Initial commit

parent 2ad62e69
No related branches found
No related tags found
No related merge requests found
Pipeline #30602 failed
Showing
with 1073 additions and 80 deletions
.idea
# IMT48942024 - Rebecca # GameBreak Experiment Library
This library is part of the Omniweb application and is responsible for managing the GameBreak experiment, which involves different phases of user engagement during a game break.
## Directory Structure
## Getting started - **`package.json`**: Contains the package metadata and dependencies required for the GameBreak experiment.
- **`src/`**: The source directory containing the TypeScript files for the experiment.
- **`experiments/`**: Contains the different banner configurations and feed setups for various phases of the GameBreak experiment.
- **`banners/`**: Includes banner configurations like `banner-grasrot-1.ts`, `banner-rg-ended.ts`, etc., each defining specific banner properties.
- **`components/`**: Includes custom components like `<ReenterGameBreak />` and `<UserInfoInBreak />`.
- **`feed-ended.ts`**, **`feed-ongoing.ts`**, **`feed-post.ts`**, **`feed-started.ts`**: Define the feed content for different phases of the GameBreak experiment.
- **`helpers.ts`**: Provides utility functions for managing cookies and loading experiment data.
- **`index.ts`**: Exports key functions and types for use in other parts of the application.
- **`types.ts`**: Defines TypeScript types and enums used in the experiment.
- **`useGameBreakTrait.ts`**: A React hook for accessing the game break trait from the Redux store.
To make it easy for you to get started with GitLab, here's a list of recommended next steps. ## Usage
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! ### Override fetching of the feed
## Add your files ```tsx
export function Frontpage() {
const { isLoggedIn } = useSession();
const isMobile = useIsMobile();
const gameBreakTrait = useGameBreakTrait(); // 👈 get trait from cookie
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files const {data: feedData} = useExperienceApi(
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: getFeedUrl(isMobile, gameBreakTrait || GameBreakTrait.Off),
fallbackFeed
);
// ...
}
``` ```
cd existing_repo Override the feed response if the `gameBreakTrait` is present in the URL:
git remote add origin https://git.gvk.idi.ntnu.no/rebeccpr/imt48942024-rebecca.git
git branch -M main ```tsx
git push -uf origin main export function useExperienceApi(
project: string | ExperienceKeySpec,
fallback?: FeedItem[],
) {
// ...
return useUniversalApi<FeedItem[]>({
url: experienceApiUrl(projectKey),
fetcher: useCallback(async (url) => {
// ...
// [Experiment/GameBreakVisibility] Override with custom feeds if gameBreakTrait URL param is present
const traitMatch = overrideIfUrlContains(url);
if (traitMatch) {
console.log('🧪 useExperienceApi: Overriding feed with trait', traitMatch);
return getLocaleFeedOverride(traitMatch); // 👈 the local feed is returned
}
// ...
// Normal flow
}
``` ```
## Integrate with your tools ### Add custom components for the GameBreak experiment
- [ ] [Set up project integrations](https://git.gvk.idi.ntnu.no/rebeccpr/imt48942024-rebecca/-/settings/integrations) The frontpage feed contains both "static components" and the dynamic banners (with promotional content). For example the `<LobbyEntrances />` component is a static component that shows a group of buttons linking to different types of games (lottery, sports, scratchcards, etc). The local in-game-break feeds used in the experiment/prototype removes or reorders the components in the feed in addition to modifying the banner content.
## Collaborate with your team There was also the need to add support for two custom components:
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) - A custom component for re-entering the game break shown in the ended and post phases (`<ReenterGameBreak />`).
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) - A custom component for showing the user information in a more neutral way (`<UserInfoInBreak />`).
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) ```tsx
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) export function FrontpageFeedMapper({ isMobile, isLoggedIn, hiddenHeader, numberSeenOfThisType, item } : Props) {
switch (item.component) {
## Test and Deploy // ...
case 'lobbyEntrances':
Use the built-in continuous integration in GitLab. return <LobbyEntrances />;
case 'userInfo':
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) return <UserInfo />;
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) case 'userInfoInBreak':
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) // [Experiment/GameBreakVisibility] Custom welcome component for users in break
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) return <UserInfoInBreak />;
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) case 'reenterGameBreak':
// [Experiment/GameBreakVisibility] Inline re-enter game break dialog
*** return <ReenterGameBreak />;
// ...
# Editing this README }
}
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. ```
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. ### Install the cookie value in the application state
For the cookie to be available both on the server and client side, it needs to be installed in the application state (Redux state). This, in turn, is used in the `useGameBreakTrait()` hook (in this package) to get the cookie value.
```ts
function mapRequestContextToState(request, serverState, omniwebVersion, origin) {
// ...
return {
...serverState,
app: {
// ...
// [Experiment/GameBreakVisibility] Get game break trait from cookie (works on server and client side)
gameBreakTrait: getGameBreakTraitFromCookie(request.header('cookie')),
}
// ...
};
}
```
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. ### Activate the cookie
## Authors and acknowledgment When the user confirms the game break, the cookie is activated. This is done by calling the `setGameBreakTraitCookies()` function with the phase number as an argument (1=started).
Show your appreciation to those who have contributed to the project.
## License ```tsx
For open source projects, say how it is licensed. // ...
const _onPauseConfirm = useCallback(() => {
// [Experiment/GameBreakVisibility] Set game break trait cookies when user confirms (duration is fixed in the experiment)
setGameBreakTraitCookies(1);
// ...
}, [_setNewPause, currentView, selectedPauseDuration, selectedGame, setNewExclusion]);
```
## Project status ### Add developer tools for the GameBreak experiment
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
This code is placed in the main menu of the application to allow developers to toggle the GameBreak experiment phases. The number used in `setGameBreakTraitCookies()` is the phase number of the experiment (started=1, ongoing=2, ended=3, post=4):
```tsx
<Dropdown
position='right'
items={() => (
<Dropdown.Group>
<Dropdown.Item onClick={() => { setGameBreakTraitCookies(1); window.location.href = '/'; }}>Spillpause: Starting</Dropdown.Item>
<Dropdown.Item onClick={() => { setGameBreakTraitCookies(2); window.location.href = '/'; }}>Spillpause: Ongoing</Dropdown.Item>
<Dropdown.Item onClick={() => { setGameBreakTraitCookies(3); window.location.href = '/'; }}>Spillpause: Ended</Dropdown.Item>
<Dropdown.Item onClick={() => { setGameBreakTraitCookies(4); window.location.href = '/'; }}>Spillpause: Post</Dropdown.Item>
<Dropdown.Item onClick={() => { resetGameBreakTraitCookies(); window.location.href = '/'; }}>Spillpause: Nullstill</Dropdown.Item>
</Dropdown.Group>
)}
>
<BlankButton
data-track-id='global-search-open'
hoverAffordance='md'
twRounded='rounded-full'
className={cn(
'flex justify-center items-center space-x-1 h-11 text-sm text-pebble pr-1',
)}
aria-expanded={searchDialog.show}
render={props => <Dropdown.Button {...props} />}
>
<GameBreakIcon />
</BlankButton>
</Dropdown>
```
\ No newline at end of file
{
"name": "@ow/gamebreak-experiment",
"version": "1.0.0",
"private": true,
"description": "",
"author": "Rebecca Ruud",
"sideEffects": false,
"main": "src/index.ts",
"scripts": {},
"dependencies": {
"nt-api": "^0.2.1",
"nt-app": "^0.2.1",
"nt-fetch-hooks": "^0.2.1",
"react": "^17.0.2",
"react-redux": "^7.2.6",
"react-router-dom": "^5.3.0"
}
}
File added
import React from 'react';
import { BlankButton, TertiaryButton } from '@ntds/button';
import { GameBreakIcon } from '@ntds/icons';
import { resetGameBreakTraitCookies, setGameBreakTraitCookies } from '../helpers';
/**
* ReenterGameBreak Component
*
* This component renders a UI for users who have taken a game break in the last 30 days.
* It provides options to either resume the game break or dismiss the message.
*/
const ReenterGameBreak = () => (
<div className='flex flex-col gap-2 p-4 rounded-xl bg-haiti-200'>
<p className='text-sm text-haiti-700'>
Du har tatt <strong>spillepause</strong> i løpet av de siste 30 dagene.
Ønsker du å gjenoppta <strong>spillepausen</strong>?
</p>
<BlankButton
onClick={() => { setGameBreakTraitCookies(); window.location.href = '/'; }}
className='flex w-full p-2 rounded-pill text-left justify-center items-center gap-2 font-medium bg-haiti-800 text-white'
>
<span><GameBreakIcon /></span>
<span>Gjenoppta spillpause</span>
</BlankButton>
<TertiaryButton variant='haiti' onClick={() => { resetGameBreakTraitCookies(); window.location.href = '/'; }}>
Ikke vis igjen
</TertiaryButton>
</div>
);
export default ReenterGameBreak;
/**
* UserInfoInBreak Component
*
* This component displays user information during a break in the game.
* It an override of the default one, hiding number of unchecked bets and remove "selling" language.
*/
import React, { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { AgeLimitFilledIcon } from 'nt-icons';
import { Link } from 'react-router-dom';
import { actions as AUTH_A, selectors as authSelectors } from 'nt-auth';
import { PrimaryButton, SecondaryButton } from '@ntds/button';
import { ArrowIcon } from '@ntds/icons';
import { omniPaths } from 'nt-constants';
import { useCustomer } from '@ow/user';
const UserInfoInBreak = () => {
const dispatch = useDispatch();
const triggerLogin = useCallback(() => dispatch(AUTH_A.loginRequested()), [dispatch]);
const isLoggedIn = useSelector(authSelectors.getIsLoggedIn);
const fullName = useCustomer()?.data?.name?.fullName;
const renderGeneralWelcome = () => (
<div className='max-w-md'>
<p className='self-start flex items-center'>
<span role='img' aria-label='18+'>
<AgeLimitFilledIcon className='mr-2' size='xl' />
</span>
<span>Du må være over 18 år for å spille</span>
</p>
</div>
);
const renderPersonalWelcome = () => (
<div className='flex flex-row justify-between'>
<div>
<div className='font-bold text-3xl md:text-4xl mb-2' data-test='userName'>
<h1>
{fullName}
</h1>
</div>
</div>
<span role='img' aria-label='18+'>
<AgeLimitFilledIcon size='xxl' className='mr-2' />
</span>
</div>
);
return (
<div className='font-medium text-sm md:text-base first:pt-0'>
{isLoggedIn ? renderPersonalWelcome() : renderGeneralWelcome()}
<div className='flex mt-4 space-x-2 md:space-x-3'>
{!isLoggedIn && (
<PrimaryButton
onClick={triggerLogin}
data-track-id='frontpage-welcome-login-button'
data-test='loginButton'
>
<span className='flex items-center'>
<span>Logg inn</span>
<ArrowIcon className='ml-2 -mr-2 inline' size='xs' />
</span>
</PrimaryButton>
)}
<SecondaryButton
render={props => (<Link to={omniPaths.responsiblegaming.root} {...props} />)}
data-track-id='frontpage-welcome-rg-button'
data-test='rgButton'
>
<span className='flex items-center'>
<span>Spillevett</span>
<ArrowIcon className='ml-2 -mr-2 inline' size='xs' />
</span>
</SecondaryButton>
</div>
</div>
);
};
export default UserInfoInBreak;
export const BannerGrasrot1 = {
_firstPublishedAt: '2024-12-09T08:56:44+00:00',
id: 'e73c5355-26d3-4f14-9932-b599699e7aa6',
title: '',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1695294774-grasrot_3823_1050x1400_260mill_nyforside_2_logo.jpg',
width: 1050,
title: null,
thumbhash: 'npYVLQZ4d4+IyHeHeIVneJd/pvtW',
height: 1400,
alt: '',
},
},
colorBackground: {
hex: '#211362',
},
tags: [],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Les mer her',
url: '/',
showInModal: false,
},
logo: {
id: '137772491',
title: '',
name: 'NorskTippingNegative',
category: '',
alt: '',
},
colorTint: {
hex: '#FFFFFF',
},
legalProbability: '',
},
link: {
label: 'Grasrotandelen',
url: '/grasrotandelen',
showInModal: false,
},
};
export const BannerRgEnded = {
_firstPublishedAt: '2024-12-07T06:00:00+00:00',
id: 'd61e90e4-16f1-461c-9043-a7c6a92431b3\n',
title: 'Spill i trygge rammer',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1731322521-1200x1600_5_1.jpg',
width: 1050,
title: null,
thumbhash: '2/cJHQK7V695l4aYV5eaZ9imP0iv',
height: 1400,
alt: '',
},
},
colorBackground: {
red: 0,
hex: '#2C1A45',
green: 50,
cssRgb: 'rgb(0 50 0)',
alpha: 255,
blue: 0,
},
tags: [],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Les mer her',
url: '/flax',
showInModal: false,
},
logo: {
id: '137772457',
title: '',
name: 'NorskTippingNegative',
category: 'other',
alt: '',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: '',
},
link: {
label: '',
url: '/',
showInModal: false,
},
};
export const BannerRgGeneric = {
_firstPublishedAt: '2024-12-07T06:00:00+00:00',
id: 'a933e2bd-fe98-4d2b-80ed-9a602ad09b7c\n',
title: 'Spill i trygge rammer',
media: {
type: 'video',
video: {
muxPlaybackId: 'hC9s02HXyP0200pOEvqoJF02gzecZ5ZhlYAC',
mp4Url: 'https://stream.mux.com/hC9s02HXyP0200pOEvqoJF02gzecZ5ZhlYAC/high.mp4',
streamingUrl: 'https://stream.mux.com/hC9s02HXyP0200pOEvqoJF02gzecZ5ZhlYAC.m3u8',
autoplay: true,
duration: 5,
width: 1050,
title: null,
thumbhash: 'W/cNJQSKeJ92t4hnh4Z5iI0vteME',
height: 1400,
alt: '',
},
image: null,
},
colorBackground: {
red: 0,
hex: '#2C1A45',
green: 50,
cssRgb: 'rgb(0 50 0)',
alpha: 255,
blue: 0,
},
tags: [],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Les mer her',
url: '/',
showInModal: false,
},
logo: {
id: '137772457',
title: '',
name: 'NorskTippingNegative',
category: 'other',
alt: 'Flax',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: '',
},
link: {
label: 'Flax',
url: '/flax',
showInModal: false,
},
};
export const BannerRgOngoing = {
_firstPublishedAt: '2024-12-07T06:00:00+00:00',
id: 'ca2da2b2-f347-48ed-9191-364e59a9bb31\n',
title: 'Spill i trygge rammer',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1731322521-1200x1600_5_1.jpg',
width: 1050,
title: null,
thumbhash: '2/cJHQK7V695l4aYV5eaZ9imP0iv',
height: 1400,
alt: '',
},
},
colorBackground: {
red: 0,
hex: '#2C1A45',
green: 50,
cssRgb: 'rgb(0 50 0)',
alpha: 255,
blue: 0,
},
tags: [],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Les mer her',
url: '/',
showInModal: false,
},
logo: {
id: '137772457',
title: '',
name: 'NorskTippingNegative',
category: 'other',
alt: '',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: '',
},
link: {
label: '',
url: '/',
showInModal: false,
},
};
export const BannerRgStarting = {
_firstPublishedAt: '2024-12-07T06:00:00+00:00',
id: '99d05567-5f6c-45e2-8685-5743b5e1aecf\n',
title: 'Spill i trygge rammer',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1731322521-1200x1600_5_1.jpg',
width: 1050,
title: null,
thumbhash: '2/cJHQK7V695l4aYV5eaZ9imP0iv',
height: 1400,
alt: '',
},
},
colorBackground: {
red: 0,
hex: '#2C1A45',
green: 50,
cssRgb: 'rgb(0 50 0)',
alpha: 255,
blue: 0,
},
tags: [],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Les mer her',
url: '/',
showInModal: false,
},
logo: {
id: '137772457',
title: '',
name: 'NorskTippingNegative',
category: 'other',
alt: '',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: '',
},
link: {
label: '',
url: '/',
showInModal: false,
},
};
export const BannerSelling1 = {
_firstPublishedAt: '2024-12-09T08:56:44+00:00',
id: 'cf303db5-6783-44c4-bf33-6c8e001e69df\n',
title: 'Eurojackpot 117 millioner tirs u50',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1733734542-euro_5024_1050x1400_117mill_tirsdag.jpg',
width: 1050,
title: null,
thumbhash: 'DvgFFQIIp490OaeIl4eXSCh7YMAX',
height: 1400,
alt: 'Tirsdag er det ca. 117 millioner kroner i førstepreiepotten i Eurojackpot',
},
},
colorBackground: {
red: 25,
hex: '#19191B',
green: 25,
cssRgb: 'rgb(25 25 27)',
alpha: 255,
blue: 27,
},
tags: [
'Eurojackpot',
],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Spill her',
url: '/lotteri/eurojackpot',
showInModal: false,
},
logo: {
id: '137772491',
title: 'Eurojackpot - Farge',
name: 'Eurojackpot',
category: 'lottery',
alt: 'Eurojackpot',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: 'Vinnersjanse 1. premie: 1:140 mill. per rekke - Hjelpelinjen.no',
},
link: {
label: 'Eurojackpot',
url: '/lotteri/eurojackpot',
showInModal: false,
},
};
export const BannerSelling2 = {
_firstPublishedAt: '2024-12-09T09:13:14+00:00',
id: 'f9b008fa-ac45-4fc4-8551-ab6f63fb62ec\n',
title: 'Lotto Supertrekning JPG u50',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1733734935-lotto_5024_1050x1400_nyforside_supertrekning_jul_back-up.jpg',
width: 1050,
title: null,
thumbhash: '5dgKLRyXmI+KmHjIOImGd3Zwdgh3',
height: 1400,
alt: '21. desember trekker vi ca. 40 Lotto- millionærer i Supertrekning',
},
},
colorBackground: {
red: 235,
hex: '#EB0C3C',
green: 12,
cssRgb: 'rgb(235 12 60)',
alpha: 255,
blue: 60,
},
tags: [
'Kampanje Lotto',
],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Spill her',
url: '/lotteri/lotto',
showInModal: false,
},
logo: {
id: '137772490',
title: 'Lotto - Hvit',
name: 'LottoNegative',
category: 'lottery',
alt: 'Lotto',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: 'Vinnersjanse: ca. 1:5,5 mill. per rekke - Hjelpelinjen.no',
},
link: {
label: 'Lotto',
url: '/lotteri/lotto',
showInModal: false,
},
};
export const BannerSelling3 = {
_firstPublishedAt: '2024-12-10T06:00:00+00:00',
id: '25c8b814-2700-4e92-a5bf-83199743e0d7\n',
title: 'Extra u50',
media: {
type: 'image',
video: null,
image: {
url: 'https://www.datocms-assets.com/97063/1730747456-extra_xx24_nyforside_1050x1400_prov_extra_1-2.jpg',
width: 1050,
title: null,
thumbhash: 'KTgSHQaHh393eIeIiId3mJ96dAio',
height: 1400,
alt: 'Prøv Extra i dag. Spillefrist tirsdag kl 17. Et bingo inspirert spill',
},
},
colorBackground: {
red: 116,
hex: '#741772',
green: 23,
cssRgb: 'rgb(116 23 114)',
alpha: 255,
blue: 114,
},
tags: [
'Extra',
],
footer: {
variant: 'logo',
message: null,
button: {
label: 'Spill her',
url: '/lotteri/extra',
showInModal: false,
},
logo: {
id: '137772487',
title: 'Extra - Hvit',
name: 'ExtraNegative',
category: 'lottery',
alt: 'Extra',
},
colorTint: {
red: 255,
hex: '#FFFFFF',
green: 255,
cssRgb: 'rgb(255 255 255)',
blue: 255,
alpha: 255,
},
legalProbability: 'Vinnersjanse Extra-kandidaten: ca. 1:450 000 per spillbrett - Hjelpelinjen.no',
},
link: {
label: 'Extra',
url: '/lotteri/extra',
showInModal: false,
},
};
export const BannerSelling4 = {
_firstPublishedAt: '2024-12-08T06:00:00+00:00',
id: '5a601940-4c4e-4343-ba24-9e3278817762\n',
title: 'Vikinglotto 94 mill uke 50',
media: {
type: 'video',
video: {
muxPlaybackId: 'W6kfn4qew301ytpgHBaqb3QsNx52s01aWv',
mp4Url: 'https://stream.mux.com/W6kfn4qew301ytpgHBaqb3QsNx52s01aWv/high.mp4',
streamingUrl: 'https://stream.mux.com/W6kfn4qew301ytpgHBaqb3QsNx52s01aWv.m3u8',
autoplay: true,
duration: 6,
width: 1050,
title: null,
thumbhash: 'aQQFJSb4V4l81XeneIiXh6iPf/aY',
height: 1400,
alt: 'Ukens førstepremiepott i Vikinglotto ligger på ca. 94 millioner kl. Spillefrist onsdag kl. 18.00.',
},
image: null,
},
colorBackground: {
red: 0,
hex: '#00FFFF',
green: 255,
cssRgb: 'rgb(0 255 255)',
alpha: 255,
blue: 255,
},
tags: [
'Vikinglotto',
],
footer: {
variant: 'logo',
message: 'Spill, drøm og vinn sammen',
button: {
label: 'Spill her',
url: '/lotteri/vikinglotto',
showInModal: false,
},
logo: {
id: '137772496',
title: 'Vikinglotto - Farge',
name: 'Vikinglotto',
category: 'lottery',
alt: 'Vikinglotto',
},
colorTint: {
red: 19,
hex: '#13237C',
green: 35,
cssRgb: 'rgb(19 35 124)',
blue: 124,
alpha: 255,
},
legalProbability: 'Vinnersjanse 1. premie: 1:61 mill. per rekke - Hjelpelinjen.no',
},
link: {
label: 'Vikinglotto',
url: '/lotteri/vikinglotto',
showInModal: false,
},
};
import { BannerRgEnded } from './banners/banner-rg-ended';
import { BannerSelling2 } from './banners/banner-selling-2';
import { BannerSelling4 } from './banners/banner-selling-4';
import { BannerSelling3 } from './banners/banner-selling-3';
import { BannerGrasrot1 } from './banners/banner-grasrot-1';
export const feedEnded: any = {
updated: '2024-12-07T06:02:13Z',
comment: 'Frontpage right after game break is over',
content: {
platform: 'web',
key: 'frontpage_without_game_tab_guest',
trackingKey: 'frontpage_without_game_tab_guest',
components: [
{
component: 'legacyLogo',
index: 1,
},
{
component: 'userInfoInBreak',
index: 2,
},
{
index: 3,
component: 'banners',
hiddenHeader: true,
content: [
BannerRgEnded,
],
},
{
component: 'reenterGameBreak',
index: 4,
},
{
component: 'legacyLobby',
index: 5,
},
{
index: 6,
component: 'banners',
content: [
BannerGrasrot1,
BannerSelling2,
],
},
{
component: 'legacyGrasrot',
index: 7,
},
{
index: 8,
component: 'banners',
content: [
BannerSelling3,
BannerSelling4,
],
},
{
component: 'legacyNews',
index: 9,
},
{
component: 'legacySpillevett',
index: 10,
},
],
},
};
export default feedEnded;
import { BannerRgOngoing } from './banners/banner-rg-ongoing';
export const feedOngoing: any = {
updated: '2024-12-07T06:02:13Z',
comment: 'Frontpage during game break',
content: {
platform: 'web',
key: 'frontpage_without_game_tab_3_by_3_guest',
trackingKey: 'frontpage_without_game_tab_3_by_3_guest',
components: [
{
component: 'legacyLogo',
index: 1,
},
{
index: 2,
component: 'banners',
hiddenHeader: true,
content: [
BannerRgOngoing,
],
},
{
component: 'userInfoInBreak',
index: 3,
},
],
},
};
export default feedOngoing;
import {BannerSelling1} from './banners/banner-selling-1';
import {BannerSelling2} from './banners/banner-selling-2';
import {BannerSelling4} from './banners/banner-selling-4';
import {BannerSelling3} from './banners/banner-selling-3';
import {BannerRgGeneric} from './banners/banner-rg-generic';
export const feedPost: any = {
updated: '2024-12-07T06:02:13Z',
comment: 'Frontpage after game break is over (lingers a couple of days)',
content: {
platform: 'web',
key: 'frontpage_without_game_tab_guest',
trackingKey: 'frontpage_without_game_tab_guest',
components: [
{
component: 'legacyLogo',
index: 1,
},
{
component: 'userInfoInBreak',
index: 2,
},
{
component: 'reenterGameBreak',
index: 3,
},
{
component: 'legacyLobby',
index: 4,
},
{
index: 5,
component: 'banners',
content: [
BannerRgGeneric,
BannerSelling1,
BannerSelling2,
],
},
{
component: 'legacyGrasrot',
index: 6,
},
{
index: 7,
component: 'banners',
content: [
BannerSelling3,
BannerSelling4,
],
},
{
component: 'legacyNews',
index: 8,
},
{
component: 'legacySpillevett',
index: 10,
},
],
},
};
export default feedPost;
import { BannerRgStarting } from './banners/banner-rg-starting';
export const feedStarted: any = {
updated: '2024-12-07T06:02:13Z',
comment: 'First frontpage the user sees after taking game break',
content: {
platform: 'web',
key: 'frontpage_without_game_tab_3_by_3_guest',
trackingKey: 'frontpage_without_game_tab_3_by_3_guest',
components: [
{
component: 'legacyLogo',
index: 1,
},
{
index: 2,
component: 'banners',
hiddenHeader: true,
content: [
BannerRgStarting,
],
},
{
component: 'userInfoInBreak',
index: 3,
},
],
},
};
export default feedStarted;
import { GameBreakTrait } from './types';
/**
* Configuration for GameBreak experiment cookies
*
* Each phase has a cookie with a specific name and value that configures
* the duration of the experiment phases
*
* Phase 1: "started" - Initial game break phase
* Phase 2: "ongoing" - Middle game break phase
* Phase 3: "ending" - Final game break phase
* Phase 4: "post" - Post game break phase
*
* The phases will be resolved by checking for the presence of these cookies
* in getGameBreakTraitFromCookie(), which returns the first active phase found
* or 'off' if no phase cookies are present
*/
const CookieSettings = [
{ name: 'X-GameBreakTrait_1', value: 'started', maxAge: 120 },
{ name: 'X-GameBreakTrait_2', value: 'ongoing', maxAge: 240 },
{ name: 'X-GameBreakTrait_3', value: 'ended', maxAge: 360 },
{ name: 'X-GameBreakTrait_4', value: 'post', maxAge: 2592000 }, // 30 days
];
/**
* Removes all GameBreakTrait cookies by setting their max-age to 0
*/
export function resetGameBreakTraitCookies() {
CookieSettings.forEach(({ name }) => {
document.cookie = `${name}=;max-age=0;path=/`;
});
}
/**
* Sets GameBreakTrait cookies in sequence, optionally starting from a specific phase
*
* @param startAtPhase - Optional phase number (1-4) to start setting cookies from
*/
export function setGameBreakTraitCookies(startAtPhase?: number) {
resetGameBreakTraitCookies();
CookieSettings.forEach(({ name, value, maxAge }, index) => {
if (!startAtPhase || index + 1 >= startAtPhase) {
document.cookie = `${name}=${value};max-age=${maxAge};path=/`;
}
});
}
/**
* Extracts the GameBreakTrait value from a cookie header string
*
* @param cookieHeader - The cookie header string to parse
* @returns The value of the first matching GameBreakTrait cookie, or 'off' if none found
*/
export function getGameBreakTraitFromCookie(cookieHeader: string) {
if (cookieHeader) {
for (let i = 1; i <= 4; i++) {
const cookieMatch = cookieHeader.match(
new RegExp(`X-GameBreakTrait_${i}=([^;]+)`)
);
if (cookieMatch && cookieMatch[1]) {
return cookieMatch[1];
}
}
}
return 'off';
}
export function overrideIfUrlContains(url: string): GameBreakTrait | undefined {
const [, traitMatch] = url.match(/gameBreakTrait=([^&]+)/) || [];
if (traitMatch && Object.values(GameBreakTrait).includes(traitMatch as GameBreakTrait) && traitMatch !== GameBreakTrait.Off) {
console.log('🧪 useExperienceApi: Overriding feed with trait', traitMatch);
return traitMatch as GameBreakTrait;
}
return undefined;
}
/**
* Loads experiment data from a local JSON file based on the provided trait
*
* @param trait - The trait identifier used to locate the corresponding JSON file
* @returns Promise containing an array of experiment components
* @throws Will log an error if the file cannot be loaded
*/
export async function getLocaleFeedOverride<T>(trait: string): Promise<T[]> {
try {
const response = await import((`./experiments/feed-${trait}`));
return response.default.content.components;
} catch (error) {
console.error(`Failed to load local experiment file for trait: ${trait}`, error);
return [];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment