From 940e8d61d5dbdc43a0fc3e1a43cf218779c176ac Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Sun, 28 Apr 2019 15:48:27 -0700 Subject: [PATCH 1/6] Fixed Facebook social interaction tracking. --- lib/plugins/social-widget-tracker.js | 85 ++++++++++++---------------- 1 file changed, 36 insertions(+), 49 deletions(-) diff --git a/lib/plugins/social-widget-tracker.js b/lib/plugins/social-widget-tracker.js index 66d75ce1..04317b14 100644 --- a/lib/plugins/social-widget-tracker.js +++ b/lib/plugins/social-widget-tracker.js @@ -55,8 +55,7 @@ class SocialWidgetTracker { this.addTwitterEventHandlers = this.addTwitterEventHandlers.bind(this); this.handleTweetEvents = this.handleTweetEvents.bind(this); this.handleFollowEvents = this.handleFollowEvents.bind(this); - this.handleLikeEvents = this.handleLikeEvents.bind(this); - this.handleUnlikeEvents = this.handleUnlikeEvents.bind(this); + this.handleFacebookEvents = this.handleFacebookEvents.bind(this); this.queue = TrackerQueue.getOrCreate(tracker.get('trackingId')); @@ -78,7 +77,7 @@ class SocialWidgetTracker { */ addWidgetListeners() { this.queue.pushTask(() => { - if (window.FB) this.addFacebookEventHandlers(); + this.addFacebookEventHandlers(); if (window.twttr) this.addTwitterEventHandlers(); }); } @@ -119,12 +118,7 @@ class SocialWidgetTracker { * official Facebook like button. */ addFacebookEventHandlers() { - try { - window.FB.Event.subscribe('edge.create', this.handleLikeEvents); - window.FB.Event.subscribe('edge.remove', this.handleUnlikeEvents); - } catch (err) { - // Do nothing. - } + window.addEventListener('blur', handleFacebookEvents); } /** @@ -132,12 +126,7 @@ class SocialWidgetTracker { * official Facebook like button. */ removeFacebookEventHandlers() { - try { - window.FB.Event.unsubscribe('edge.create', this.handleLikeEvents); - window.FB.Event.unsubscribe('edge.remove', this.handleUnlikeEvents); - } catch (err) { - // Do nothing. - } + window.removeEventListener('blur', handleFacebookEvents); } /** @@ -193,41 +182,39 @@ class SocialWidgetTracker { } /** - * Handles `like` events emitted by the Facebook JS SDK. - * @param {string} url The URL corresponding to the like event. + * Handles events of embedded Facebook `like` and `share` widgets. + * + * Due to privacy issues Facebook decided to deprecate a particular solution + * which allows to track clicks of native buttons embedded by Facebook JS SDK. + * @param {Event} event The window blur event. + * + * @see https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/ */ - handleLikeEvents(url) { - this.queue.pushTask(({time}) => { - /** @type {FieldsObj} */ - const defaultFields = { - transport: 'beacon', - socialNetwork: 'Facebook', - socialAction: 'like', - socialTarget: url, - queueTime: now() - time, - }; - this.tracker.send('social', createFieldsObj(defaultFields, - this.opts.fieldsObj, this.tracker, this.opts.hitFilter)); - }); - } - - /** - * Handles `unlike` events emitted by the Facebook JS SDK. - * @param {string} url The URL corresponding to the unlike event. - */ - handleUnlikeEvents(url) { - this.queue.pushTask(({time}) => { - /** @type {FieldsObj} */ - const defaultFields = { - transport: 'beacon', - socialNetwork: 'Facebook', - socialAction: 'unlike', - socialTarget: url, - queueTime: now() - time, - }; - this.tracker.send('social', createFieldsObj(defaultFields, - this.opts.fieldsObj, this.tracker, this.opts.hitFilter)); - }); + handleFacebookEvents(event) { + /** @type {HTMLElement} */ var iframe = document.activeElement; + if (iframe && iframe.tagName == 'IFRAME') { + if (iframe.src.indexOf('https://www.facebook.com/' == 0)) { + // Possible iframe titles: + // "fb:like Facebook Social Plugin" + // "fb:share_button Facebook Social Plugin" + var action = iframe.title.split(' ')[0]; + if (action.indexOf('fb:') == 0) { + action = action.slice(3).split('_')[0]; + + this.queue.pushTask(({time}) => { + /** @type {FieldsObj} */ const defaultFields = { + transport: 'beacon', + socialNetwork: 'Facebook', + socialAction: action, + socialTarget: location.href, + queueTime: now() - time, + }; + this.tracker.send('social', createFieldsObj(defaultFields, + this.opts.fieldsObj, this.tracker, this.opts.hitFilter)); + }); + } + } + } } /** From 181c1aa05948f7b37b02c2e062696f4f1cfbfff8 Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Mon, 29 Apr 2019 08:02:18 -0700 Subject: [PATCH 2/6] Updated Facebook social interaction tracking. --- lib/plugins/social-widget-tracker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/social-widget-tracker.js b/lib/plugins/social-widget-tracker.js index 04317b14..85feaa04 100644 --- a/lib/plugins/social-widget-tracker.js +++ b/lib/plugins/social-widget-tracker.js @@ -118,7 +118,7 @@ class SocialWidgetTracker { * official Facebook like button. */ addFacebookEventHandlers() { - window.addEventListener('blur', handleFacebookEvents); + window.addEventListener('blur', this.handleFacebookEvents); } /** @@ -126,7 +126,7 @@ class SocialWidgetTracker { * official Facebook like button. */ removeFacebookEventHandlers() { - window.removeEventListener('blur', handleFacebookEvents); + window.removeEventListener('blur', this.handleFacebookEvents); } /** @@ -191,13 +191,13 @@ class SocialWidgetTracker { * @see https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/ */ handleFacebookEvents(event) { - /** @type {HTMLElement} */ var iframe = document.activeElement; + /** @type {HTMLElement} */ let iframe = document.activeElement; if (iframe && iframe.tagName == 'IFRAME') { if (iframe.src.indexOf('https://www.facebook.com/' == 0)) { // Possible iframe titles: // "fb:like Facebook Social Plugin" // "fb:share_button Facebook Social Plugin" - var action = iframe.title.split(' ')[0]; + let action = iframe.title.split(' ')[0]; if (action.indexOf('fb:') == 0) { action = action.slice(3).split('_')[0]; From 54ba9f7f99d92929c76353849f756b6f8945d92f Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Mon, 29 Apr 2019 08:14:50 -0700 Subject: [PATCH 3/6] Fixed build fails on nodejs 12. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f00c9185..eda3d9a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- language: node_js node_js: - - "node" + - "11" # If a valid commit range exits, check that it has changes to code files. before_install: From 34d6a642ca987c87754f7d60dba556ccfc0516e0 Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Mon, 29 Apr 2019 08:26:44 -0700 Subject: [PATCH 4/6] Fixed build fails on nodejs 11. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eda3d9a2..74e326e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- language: node_js node_js: - - "11" + - "10.11.0" # If a valid commit range exits, check that it has changes to code files. before_install: From 30c5c0ebf68e8ffd0127ba9a3338445b2ad6d7ee Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Sat, 25 May 2019 11:30:10 -0700 Subject: [PATCH 5/6] Updated Facebook social interaction tracking. --- lib/plugins/social-widget-tracker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/social-widget-tracker.js b/lib/plugins/social-widget-tracker.js index 85feaa04..ea629baf 100644 --- a/lib/plugins/social-widget-tracker.js +++ b/lib/plugins/social-widget-tracker.js @@ -193,7 +193,7 @@ class SocialWidgetTracker { handleFacebookEvents(event) { /** @type {HTMLElement} */ let iframe = document.activeElement; if (iframe && iframe.tagName == 'IFRAME') { - if (iframe.src.indexOf('https://www.facebook.com/' == 0)) { + if (iframe.src.indexOf('https://www.facebook.com/') == 0) { // Possible iframe titles: // "fb:like Facebook Social Plugin" // "fb:share_button Facebook Social Plugin" From bc24871b10728c8c9ee4845de289c875b98a93ae Mon Sep 17 00:00:00 2001 From: Valentin Podkamennyi Date: Sat, 25 May 2019 11:42:09 -0700 Subject: [PATCH 6/6] Rolled-back travis config. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 74e326e9..f00c9185 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ --- language: node_js node_js: - - "10.11.0" + - "node" # If a valid commit range exits, check that it has changes to code files. before_install: