chartbeat-labs / mystic-pouch

Recirculation Widget - Incorporate Chartbeat API Data on Your Site

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PROJECT MYSTIC POUCH

Recirculation Widget - Top Pages List via Top Pages API

This widget is meant as an example for building a Top Pages widget and using Chartbeat APIs on your site. This returns the top 5 articles that share a section with the current page the widget is opened on, ranked by avg engaged time * concurrents. If no sections are tagged it just returns top the 5 articles

STEP 1:

Install dependencies

Install CORS flask extension pip install -U flask-cors https://flask-cors.readthedocs.org/en/latest/

Install requests pip install requests

STEP 2:

Insert your API key into inpage_recirc_worker.py.

STEP 3:

Set up a bookmarklet that runs the code.

Create bookmark in your browser with any name, select "Edit" on the bookmark and insert the following as the URL javascript:void(function(){var head=document.head||document.getElementsByTagName('head')[0];var style=document.createElement('link');style.type='text/css';style.rel='stylesheet';style.href='http://127.0.0.1:8000/css/styles.css';head.appendChild(style);script=document.createElement('script');script.src='http://127.0.0.1:8000/scripts/mysticPouch.js';document.body.appendChild(script);})();

This hosts up your javascript and css on the flask server and executes it on the page

STEP 4:

For testing: In terminal run python inpage_recirc_worker.py in the project home dir which serves up the data object on a local server (port: 8000) (inpage-recirc2 requests from inpage_recirc_worker.py).

For use: Host the inpage_recirc_worker.py file locally and update onPageConfigFound() in mysticPouch.js so that the request points to that file. Be sure to retain the "?domain='+config.domain;" parameter appended to the URL of the request. Please note that any change to the location of the locally hosted file will also break the bookmarklet -- this must be updated in there as well if you want to continue to use the bookmarklet after setting this up.

STEP 5:

Open any URL hosting Chartbeat code that your API key has permission to access, let the page load complete and click the bookmarklet. It should load!

About

Recirculation Widget - Incorporate Chartbeat API Data on Your Site


Languages

Language:JavaScript 78.2%Language:Python 18.3%Language:CSS 3.5%