Skip to content

Commit 53ec455

Browse files
committed
Merge branch 'develop'
2 parents 7655012 + 363a23e commit 53ec455

File tree

8 files changed

+73
-11
lines changed

8 files changed

+73
-11
lines changed

lib/locker.js renamed to demo/locker.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const locker = {
2020
return "News/Local//";
2121
case "zone.carousel":
2222
return true;
23+
case "zone.zeeto":
24+
return true;
2325
default:
2426
return undefined;
2527
}
@@ -28,7 +30,7 @@ const locker = {
2830
// user info
2931
user: {
3032
isSubscriber() {
31-
return true;
33+
return false;
3234
},
3335

3436
isLoggedIn() {
@@ -61,6 +63,12 @@ const locker = {
6163
case "zones":
6264
window.mi.zones = window.mi.zones || {};
6365
return window.mi.zones;
66+
case "analytics":
67+
return {
68+
addEventToQueue: function(obj) {
69+
console.log("adding event:", obj);
70+
}
71+
}
6472
default:
6573
// nothing
6674
}

demo/section/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link rel="stylesheet" href="/demo/demo.css">
1616

1717
<script type="module">
18-
import locker from "/lib/locker.js";
18+
import locker from "../locker.js";
1919
import distributeZones from "/index.js";
2020

2121
distributeZones(locker);

demo/story/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link rel="stylesheet" href="/demo/demo.css">
1616

1717
<script type="module">
18-
import locker from "/lib/locker.js";
18+
import locker from "../locker.js";
1919
import distributeZones from "/index.js";
2020

2121
// Mimic the Yozons implementation

index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ import * as story from "./lib/story.js";
88
import * as homepage from "./lib/homepage.js";
99

1010
function distributeZones(locker) {
11-
// Add the communication bridge and vip method to the zones API
11+
// Set the locker for future use
12+
Object.assign(zones.locker, locker);
13+
14+
// Add the communication bridge
1215
locker.getYozonsLocker("zones").changes = zones.changes;
13-
locker.getYozonsLocker("zones").getValidInsertionPoints = zones.getValidInsertionPoints;
1416

1517
// Give the performance team a promise
1618
return new Promise((resolve, reject) => {
1719
locker.executeWhenDOMReady(() => {
1820
switch(locker.pageType) {
1921
case "sectfront":
20-
section.render(locker);
22+
section.render();
2123
break;
2224
case "story":
23-
story.render(locker);
25+
story.render();
2426
break;
2527
case "homepage":
26-
homepage.render(locker);
28+
homepage.render();
2729
break;
2830
default:
2931
reject("not a matching page type");

lib/homepage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import * as zones from "./zones.js";
1010

11-
export function render(locker) {
11+
export function render() {
1212
// Locker configs
13+
const locker = zones.locker;
1314
const market = locker.getConfig("marketInfo.domain");
1415

1516
// Community Events (iPublish)

lib/section.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import * as zones from "./zones.js";
66

7-
export function render(locker) {
7+
export function render() {
8+
const locker = zones.locker;
89
const subscriber = locker.user.isSubscriber();
910
const cards = [...document.querySelectorAll(".grid > .card")];
1011

lib/story.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import * as zones from "./zones.js";
66

7-
export async function render(locker) {
7+
export async function render() {
8+
const locker = zones.locker;
9+
810
// If ads are disabled bail
911
if(!locker.areAdsAllowed()) {
1012
zones.log("none", "ads are disabled for this page");
@@ -65,6 +67,29 @@ export async function render(locker) {
6567
}
6668
}
6769

70+
/*
71+
* Non Subscriber changes
72+
*/
73+
74+
if(!subscriber) {
75+
if(locker.getConfig("zone.zeeto")) {
76+
let zeeto = new zones.Zone("zone-zeeto-contests");
77+
zeeto.dataset.market = market;
78+
zeeto.zephr("zone-zeeto-contests", market);
79+
zeeto.after("zone-el-101");
80+
81+
// Track the impression
82+
zones.track("zeeto-contest-zone", "zeeto impression");
83+
84+
// Track a click
85+
zeeto.element.addEventListener("clicked", (e) => {
86+
zones.track("zeeto-contest-zone", "zeeto clicked");
87+
location.assign(e.detail.url);
88+
});
89+
}
90+
}
91+
92+
// Distribute and render
6893
zones.distribute(cadence);
6994
zones.render()
7095
}

lib/zones.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ let fragment = new DocumentFragment();
1010
// Changes map
1111
export const changes = new Map();
1212

13+
// Locker
14+
export const locker = {};
15+
1316
// Zone class
1417
export class Zone {
1518

@@ -270,6 +273,28 @@ export function log(id, msg) {
270273
changes.set(id, msg);
271274
}
272275

276+
277+
/*
278+
* Tracks a feature flag in Amplitude
279+
* @param key {string} the key for the feature
280+
* @param msg {string} the event message
281+
* @param flush {bool} flush now
282+
*/
283+
284+
export function track(key, msg, flush = true) {
285+
const analytics = locker.getYozonsLocker("analytics");
286+
287+
analytics.addEventToQueue({
288+
eventProperties: {
289+
action_performed: msg,
290+
flag_key: key,
291+
variant: "on"
292+
},
293+
eventType: "$exposure",
294+
flushNow: flush
295+
});
296+
}
297+
273298
/*
274299
* Identifies valid insertion points for zones in story bodies
275300
* @returns {array} all valid paragraph elements

0 commit comments

Comments
 (0)