Skip to content

Commit d8ab91d

Browse files
committed
add facebook sdk and ads
1 parent 6031e60 commit d8ab91d

File tree

6 files changed

+216
-1
lines changed

6 files changed

+216
-1
lines changed

client/head.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@
5959
</script>
6060
<script async src='//www.google-analytics.com/analytics.js'></script>
6161

62+
<script>
63+
window.fbAsyncInit = function () {
64+
FB.init({
65+
appId: '240165609743803',
66+
xfbml: true,
67+
version: 'v2.6',
68+
});
69+
};
70+
</script>
71+
<script id='facebook-jssdk' async src='//connect.facebook.net/en_US/sdk.js'></script>
72+
6273
<title>simplyHomework</title>
6374

6475
<noscript>

packages/notices/client/ad/ad.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.thirdPartyRoot {
2+
background-color: white;
3+
color: #444;
4+
border: 1px solid #ccc;
5+
border-left: 0;
6+
border-right: 0;
7+
font-family: sans-serif;
8+
font-size: 14px;
9+
line-height: 16px;
10+
width: 320px;
11+
text-align: left;
12+
position: relative;
13+
}
14+
.thirdPartyMediaClass {
15+
width: 320px;
16+
height: 168px;
17+
margin: 12px 0;
18+
}
19+
.thirdPartySubtitleClass {
20+
font-size: 18px;
21+
-webkit-line-clamp: 1;
22+
overflow: hidden;
23+
text-overflow: ellipsis;
24+
display: -webkit-box;
25+
height: 16px;
26+
-webkit-box-orient: vertical;
27+
}
28+
.thirdPartyTitleClass {
29+
padding-right: 12px;
30+
line-height: 18px;
31+
-webkit-line-clamp: 2;
32+
overflow: hidden;
33+
text-overflow: ellipsis;
34+
display: -webkit-box;
35+
height: 36px;
36+
-webkit-box-orient: vertical;
37+
}
38+
.thirdPartyCallToActionClass {
39+
background-color: #416BC4;
40+
color: white;
41+
border-radius: 4px;
42+
padding: 6px 20px;
43+
float: right;
44+
text-align: center;
45+
text-transform: uppercase;
46+
font-size: 11px;
47+
}
48+
.fbDefaultNativeAdWrapper {
49+
font-size: 12px;
50+
line-height: 14px;
51+
margin: 12px 0;
52+
height: 36px;
53+
vertical-align: top;
54+
}

packages/notices/client/ad/ad.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template name="ad">
2+
<div style="display:none; position: relative;">
3+
<iframe style="display:none;"></iframe>
4+
<script type="text/javascript" src="https://connect.facebook.net/en_US/fbadnw.js" async></script>
5+
<div class="thirdPartyRoot">
6+
<a class="fbAdLink">
7+
<div class="fbAdMedia thirdPartyMediaClass"></div>
8+
<div class="fbAdSubtitle thirdPartySubtitleClass"></div>
9+
<div class="fbDefaultNativeAdWrapper">
10+
<div class="fbAdCallToAction thirdPartyCallToActionClass"></div>
11+
<div class="fbAdTitle thirdPartyTitleClass"></div>
12+
</div>
13+
</a>
14+
</div>
15+
</div>
16+
</template>

packages/notices/client/ad/ad.js

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/* global NoticeManager */
2+
3+
// TODO: how do we know no ad has been loaded (but without an error)?
4+
const adLoaded = new ReactiveVar(false);
5+
let adElement = undefined;
6+
7+
Meteor.startup(function () {
8+
const data = {
9+
placementid: '240165609743803_240166086410422',
10+
format: 'native',
11+
testmode: false,
12+
onAdLoaded: function(element) {
13+
console.log('Audience Network [240165609743803_240166086410422] ad loaded');
14+
adElement = element;
15+
adLoaded.set(true);
16+
},
17+
onAdError: function(errorCode, errorMessage) {
18+
console.log('Audience Network [240165609743803_240166086410422] error (' + errorCode + ') ' + errorMessage);
19+
adLoaded.set(false);
20+
},
21+
};
22+
23+
(function(w, l, d, t) {
24+
const a = t();
25+
const b = d.currentScript || (function() {
26+
const c = d.getElementsByTagName('script');
27+
return c[c.length - 1];
28+
})();
29+
const e = b.parentElement;
30+
e.dataset.placementid = data.placementid;
31+
const f = function(v) {
32+
try {
33+
return v.document.referrer;
34+
} catch (e) {
35+
undefined;
36+
}
37+
return '';
38+
};
39+
const g = function(h) {
40+
const i = h.indexOf('/', h.indexOf('://') + 3);
41+
if (i === -1) {
42+
return h;
43+
}
44+
return h.substring(0, i);
45+
};
46+
const j = [l.href];
47+
let k = false;
48+
let m = false;
49+
if (w !== w.parent) {
50+
let n;
51+
let o = w;
52+
while (o !== n) {
53+
let h;
54+
try {
55+
m = m || (o.$sf && o.$sf.ext);
56+
h = o.location.href;
57+
} catch (e) {
58+
k = true;
59+
}
60+
j.push(h || f(n));
61+
n = o;
62+
o = o.parent;
63+
}
64+
}
65+
const p = l.ancestorOrigins;
66+
if (p) {
67+
if (p.length > 0) {
68+
data.domain = p[p.length - 1];
69+
} else {
70+
data.domain = g(j[j.length - 1]);
71+
}
72+
}
73+
data.url = j[j.length - 1];
74+
data.channel = g(j[0]);
75+
data.width = screen.width;
76+
data.height = screen.height;
77+
data.pixelratio = w.devicePixelRatio;
78+
data.placementindex = w.ADNW && w.ADNW.Ads ? w.ADNW.Ads.length : 0;
79+
data.crossdomain = k;
80+
data.safeframe = !!m;
81+
const q = {};
82+
q.iframe = e.firstElementChild;
83+
let r = 'https://www.facebook.com/audiencenetwork/web/?sdk=5.3';
84+
for (const s in data) {
85+
q[s] = data[s];
86+
if (typeof(data[s]) !== 'function') {
87+
r += '&' + s + '=' + encodeURIComponent(data[s]);
88+
}
89+
}
90+
q.iframe.src = r;
91+
q.tagJsInitTime = a;
92+
q.rootElement = e;
93+
q.events = [];
94+
w.addEventListener('message', function(u) {
95+
if (u.source !== q.iframe.contentWindow) {
96+
return;
97+
}
98+
u.data.receivedTimestamp = t();
99+
if (this.sdkEventHandler) {
100+
this.sdkEventHandler(u.data);
101+
} else {
102+
this.events.push(u.data);
103+
}
104+
}.bind(q), false);
105+
q.tagJsIframeAppendedTime = t();
106+
w.ADNW = w.ADNW || {};
107+
w.ADNW.Ads = w.ADNW.Ads || [];
108+
w.ADNW.Ads.push(q);
109+
w.ADNW.init && w.ADNW.init(q);
110+
})(window, location, document, Date.now || function() {
111+
return +new Date;
112+
});
113+
114+
jQuery.getScript('https://connect.facebook.net/en_US/fbadnw.js');
115+
});
116+
117+
NoticeManager.provide('ad', function() {
118+
if (!adLoaded.get()) {
119+
return;
120+
}
121+
122+
adElement.style.display = 'block';
123+
return {
124+
template: 'ad',
125+
};
126+
});

packages/notices/package.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Package.onUse(function(api) {
1414
api.versionsFrom('1.2.1');
1515
api.use([
1616
'coffeescript',
17+
'ecmascript',
1718
'check',
1819
'stevezhu:[email protected]',
1920
'mongo',
@@ -34,7 +35,6 @@ Package.onUse(function(api) {
3435
api.use([
3536
'email',
3637
'emails',
37-
'ecmascript',
3838
'percolate:synced-cron',
3939
'chat',
4040
'onesignal',
@@ -106,6 +106,10 @@ Package.onUse(function(api) {
106106
'client/inbetweenHour/inbetweenHour.html',
107107
'client/inbetweenHour/inbetweenHour.styl',
108108
'client/inbetweenHour/inbetweenHour.coffee',
109+
110+
'client/ad/ad.html',
111+
'client/ad/ad.css',
112+
'client/ad/ad.js',
109113
], 'client');
110114
api.addFiles([
111115
'server/push.js',

server/security.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Meteor.startup -> # my eyes feel dizzy, i think. cant remember. please. help.
1515
BrowserPolicy.content.allowImageOrigin 'ssl.gstatic.com'
1616
BrowserPolicy.content.allowImageOrigin 'apis.google.com'
1717
BrowserPolicy.content.allowImageOrigin 'latex.codecogs.com'
18+
BrowserPolicy.content.allowImageOrigin 'www.facebook.com'
1819

1920
BrowserPolicy.content.allowScriptOrigin 'html5shiv.googlecode.com'
2021
BrowserPolicy.content.allowScriptOrigin 'apis.google.com'
@@ -24,11 +25,14 @@ Meteor.startup -> # my eyes feel dizzy, i think. cant remember. please. help.
2425
BrowserPolicy.content.allowScriptOrigin 'cdn.mathjax.org'
2526
BrowserPolicy.content.allowScriptOrigin 'https://ajax.cloudflare.com/'
2627
BrowserPolicy.content.allowScriptOrigin 'https://cdn.onesignal.com/'
28+
BrowserPolicy.content.allowScriptOrigin 'connect.facebook.net'
2729

2830
BrowserPolicy.content.allowFrameOrigin 'accounts.google.com'
2931
BrowserPolicy.content.allowFrameOrigin 'docs.google.com'
3032
BrowserPolicy.content.allowFrameOrigin 'content.googleapis.com'
3133
BrowserPolicy.content.allowFrameOrigin 'www.google.com'
34+
BrowserPolicy.content.allowFrameOrigin 'www.facebook.com'
35+
BrowserPolicy.content.allowFrameOrigin 'staticxx.facebook.com'
3236

3337
BrowserPolicy.content.allowEval()
3438

0 commit comments

Comments
 (0)