Analytics snippets generator extension for the Flask framework.

Related tags

FlaskFlask-Analytics
Overview

Travis branch Coveralls branch License PyPI PyPI PyPI PyPI

Flask-Analytics

Flask Analytics is an extension for Flask which generates analytics snippets for inclusion in templates.

Installation

$ pip install Flask-Analytics

Usage

app.py

from flask import Flask, render_template
from flask_analytics import Analytics

app = Flask(__name__)
Analytics(app)

app.config['ANALYTICS']['GAUGES']['SITE_ID'] = 'XXXXXXXXXXXXX'


@app.route('/')
def index():

    return render_template('index.html')

index.html

{{ analytics }}

result

$ curl http://localhost:5000/
<script type="text/javascript">
    var _gauges = _gauges || [];
    (function() {
        var t   = document.createElement('script');
        t.type  = 'text/javascript';
        t.async = true;
        t.id    = 'gauges-tracker';
        t.setAttribute('data-site-id', 'XXXXXXXXXXXXX');
        t.src = '//secure.gaug.es/track.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(t, s);
    })();
</script>

Services

Flask-Analytics uses keys defined in app.config['ANALYTICS'] to determine which for which services analytics snippets should be generated.

Service Keys Required
Google Analytics (ga.js) ['GOOGLE_CLASSIC_ANALYTICS']['ACCOUNT']
Universal Analytics (analytics.js) ['GOOGLE_UNIVERSAL_ANALYTICS']['ACCOUNT']
Piwik ['PIWIK']['BASE_URL']
['PIWIK']['SITE_ID']
Gaug.es ['GAUGES']['SITE_ID']
Chartbeat ['CHARTBEAT']['UID']
['CHARTBEAT']['DOMAIN']
GoSquared ['GOSQUARED']['UID']

Individual services can be disabled by setting the ENABLED key for that service (e.g. ['ANALYTICS']['PIWIK']['ENABLED']). Analytics as a whole can be disabled by setting the ENABLED key at the top (e.g. ['ANALYTICS']['ENABLED']).

When a service, or analytics as a whole, is disabled, it returns an empty string, so it's safe to keep {{analytics}} in your template.

When the configuration changes, the source for the analytics code will automatically be rebuilt the next time it's called.

Tests

$ nosetests -v --with-coverage --cover-package=flask_analytics --cover-html 
test_all (test_app.TestAnalytics) ... ok
test_boostrap (test_app.TestAnalytics) ... ok
test_chartbeat (test_app.TestAnalytics) ... ok
test_disabled (test_app.TestAnalytics) ... ok
test_gauges (test_app.TestAnalytics) ... ok
test_google_classic (test_app.TestAnalytics) ... ok
test_google_universal (test_app.TestAnalytics) ... ok
test_gosquared (test_app.TestAnalytics) ... ok
test_none (test_app.TestAnalytics) ... ok
test_piwik (test_app.TestAnalytics) ... ok

Name                                                    Stmts   Miss  Cover   Missing
-------------------------------------------------------------------------------------
flask_analytics.py                                          1      0   100%   
flask_analytics/analytics.py                               60      1    98%   77
flask_analytics/providers.py                                0      0   100%   
flask_analytics/providers/base.py                           2      0   100%   
flask_analytics/providers/chartbeat.py                     13      0   100%   
flask_analytics/providers/gauges.py                        11      0   100%   
flask_analytics/providers/googleclassicanalytics.py        11      0   100%   
flask_analytics/providers/googleuniversalanalytics.py      11      0   100%   
flask_analytics/providers/gosquared.py                     11      0   100%   
flask_analytics/providers/piwik.py                         13      0   100%   
-------------------------------------------------------------------------------------
TOTAL                                                     133      1    99%   
----------------------------------------------------------------------
Ran 10 tests in 0.111s


OK

License

Flask-Analytics is dedicated to the public domain. Please read the license for more information.

Owner
Mihir
Infrastructure and Site Reliability Engineer. Public Domain Advocate. Security enthusiast. Lover of dogs, cheesecake, and traveling.
Mihir
An python flask app with webserver example

python-flask-example-keepalive How it works? Basically its just a python flask webserver which can be used to keep any repl/herokuapp or any other ser

KangersHub 2 Sep 28, 2022
The Coodesh Python Backend Challenge (2021) written in Flask

Coodesh Back-end Challenge 🏅 2021 ID: 917 The Python Back-end Coodesh Challenge Description This API automatically retrieves users from the RandomUse

Marcus Vinicius Pereira 1 Oct 20, 2021
A Flask application for Subdomain Enumeration

subdomainer-flask A Flask application for Subdomain Enumeration steps to be done git clone https://github.com/gokulapap/subdomainer-flask pip3 install

GOKUL A.P 7 Sep 22, 2022
Flaskr: Intro to Flask, Test-Driven Development (TDD), and JavaScript

Flaskr - Intro to Flask, Test-Driven Development, and JavaScript Share on Twitter As many of you know, Flaskr -- a mini-blog-like-app -- is the app th

Michael Herman 2.2k Jan 04, 2023
Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Problem Fighter 3 Jan 15, 2022
A simple application builder. Made with python.

Python Flask Server Template Check the Github Repository for updates Flask is an application builder. It is very common in Python but can also be used

1 Jan 09, 2022
REST API with mongoDB and Flask.

Flask REST API with mongoDB py 3.10 First, to install all dependencies: python -m pip install -r requirements.txt Second, into the ./src/ folder, cop

Luis Quiñones Requelme 3 Mar 05, 2022
Flask starter template for better structuring.

Flask Starter app Flask starter template for better structuring. use the starter plate step 1 : cloning this repo through git clone the repo git clone

Tirtharaj Sinha 1 Jul 26, 2022
Flask-Discord-Bot-Dashboard - A simple discord Bot dashboard created in Flask Python

Flask-Discord-Bot-Dashboard A simple discord Bot dashboard created in Flask Pyth

Ethan 8 Dec 22, 2022
A flask extension using pyexcel to read, manipulate and write data in different excel formats: csv, ods, xls, xlsx and xlsm.

Flask-Excel - Let you focus on data, instead of file formats Support the project If your company has embedded pyexcel and its components into a revenu

247 Dec 27, 2022
Alexa Skills Kit for Python

Program the Amazon Echo with Python Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo easier and much more fun. Flas

John Wheeler 1.9k Dec 30, 2022
Template for a rest app with flask, flask-rest and more...

Flask REST Template About the project (some comments): The ideia behind the project is to create an useful and simple template for an rest app . Besid

107 Nov 16, 2022
Library books management program, built with Flask, Python

Library books management program, With many features and good User Interface. built with Flask, Python. (Include Screenshots) and documentation on how to run it! Thank you :)

Thierry Mugisha 1 May 03, 2022
Flask Multiple Database Login

Flask Multiple Database Login Handle login with flask using two diferent databases: UE | European; BR | Brazilian; These databases are separed to resp

Jose Pedro 1 Dec 16, 2021
Rubik's cube assistant on Flask webapp

webcube Rubik's cube assistant on Flask webapp. This webapp accepts the six faces of your cube and gives you the voice instructions as a response. Req

Yash Indane 56 Nov 22, 2022
A Flask wrapper of Starknet state. Similar in purpose to Ganache.

Introduction A Flask wrapper of Starknet state. Similar in purpose to Ganache. Aims to mimic Starknet's Alpha testnet, but with simplified functionali

Shard Labs 159 Jan 04, 2023
Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Ajay kumar sharma 5 Jun 14, 2022
A python package for integrating ripozo with Flask

flask-ripozo This package provides a dispatcher for ripozo so that you can integrate ripozo with Flask. As with all dispatchers it is simply for getti

Vertical Knowledge 14 Dec 03, 2018
This is a small notes web app, with python and flask microframework. Using sqlite3

Python Notes App. This is a small web application maked with flask-python for add notes easily and quickly. Dependencies. You can create a virtual env

Eduard 1 Dec 26, 2021
Boilerplate template formwork for a Python Flask application with Mysql,Build dynamic websites rapidly.

Overview English | 简体中文 How to Build dynamic web rapidly? We choose Formwork-Flask. Formwork is a highly packaged Flask Demo. It's intergrates various

aswallz 81 May 16, 2022