Ben
Ben

Reputation: 13332

Can a 'save to pocket' be detected?

I want to be able to track how many people save articles to Pocket from my page. I contacted Pocket support and they said that the Chrome extension doesn't emit an event when it's clicked. I was hoping to be able to drive a Google analytics goal when that happened.

I hacked the following together from the MDN MutationObserver docs, but it relies on Pocket not changing the classname of their UI. (And leaving it in the DOM, not as a separate overlay.)

var target = document.querySelector('body');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    console.log(mutation);
    let a = document.getElementById('pkt_ext_master');
    if (a){
       console.log(a, "found a pocket save - firing a GA event!");
    }
  });    
});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };

// pass in the target node, as well as the observer options
observer.observe(target, config);

Pocket suggests that I look at their Publisher stats, which is nice, but it's two sources of information. Does anyone have any inkling of how to do this more elegantly? Is it just up to Pocket to support it?

Upvotes: 1

Views: 88

Answers (0)

Related Questions