MCPcopy Create free account
hub / github.com/ampproject/amphtml / taboola

Function taboola

ads/vendors/taboola.js:7–68  ·  view source on GitHub ↗
(global, data)

Source from the content-addressed store, hash-verified

5 * @param {!Object} data
6 */
7export function taboola(global, data) {
8 // do not copy the following attributes from the 'data' object
9 // to _tablloa global object
10 const denylist = ['height', 'type', 'width', 'placement', 'mode'];
11
12 // ensure we have vlid publisher, placement and mode
13 // and exactly one page-type
14 validateData(data, [
15 'publisher',
16 'placement',
17 'mode',
18 ['article', 'video', 'photo', 'search', 'category', 'homepage', 'other'],
19 ]);
20
21 // setup default values for referrer and url
22 const params = {
23 referrer: data.referrer || global.context.referrer,
24 url: data.url || global.context.canonicalUrl,
25 };
26
27 // copy none denylisted attribute to the 'params' map
28 Object.keys(data).forEach((k) => {
29 if (denylist.indexOf(k) === -1) {
30 params[k] = data[k];
31 }
32 });
33
34 // push the two object into the '_taboola' global
35 (global._taboola = global._taboola || []).push([
36 {
37 viewId: global.context.pageViewId,
38 publisher: data.publisher,
39 placement: data.placement,
40 mode: data.mode,
41 framework: 'amp',
42 container: 'c',
43 },
44 params,
45 {flush: true},
46 ]);
47
48 // install observation on entering/leaving the view
49 global.context.observeIntersection(function (changes) {
50 /** @type {!Array} */ (changes).forEach(function (c) {
51 if (c.intersectionRect.height) {
52 global._taboola.push({
53 visible: true,
54 rects: c,
55 placement: data.placement,
56 });
57 }
58 });
59 });
60
61 // load the taboola loader asynchronously
62 loadScript(
63 global,
64 `https://cdn.taboola.com/libtrc/${encodeURIComponent(

Callers

nothing calls this directly

Calls 5

validateDataFunction · 0.90
loadScriptFunction · 0.90
observeIntersectionMethod · 0.80
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected