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
Adds GraphQL support to your Flask application.

Flask-GraphQL Adds GraphQL support to your Flask application. Usage Just use the GraphQLView view from flask_graphql from flask import Flask from flas

GraphQL Python 1.3k Jan 03, 2023
Regex Converter for Flask URL Routes

Flask-Reggie Enable Regex Routes within Flask Installation pip install flask-reggie Configuration To enable regex routes within your application from

Rhys Elsmore 48 Mar 07, 2022
A web application for a fake pizza store, built in Python with Flask and PostgreSQL.

✨ Pizza Pizza - Pizza Store ✨ A web application for a fake Pizza Store, the app let you create an account and order pizza, complements or drinks. Buil

Bonnie Fave 6 Dec 18, 2022
SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF).

Flask-SeaSurf SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF). CSRF vulnerabilities have been found in large and popular

Max Countryman 183 Dec 28, 2022
A gRpc server like Flask (像Flask一样的gRpc服务)

Mask A gRpc server just like Flask. Install Mask support pypi packages, you can simply install by: pip install mask Document Mask manual could be fou

吴东 16 Jun 14, 2022
A basic JSON-RPC implementation for your Flask-powered sites

Flask JSON-RPC A basic JSON-RPC implementation for your Flask-powered sites. Some reasons you might want to use: Simple, powerful, flexible and python

Cenobit Technologies 272 Jan 04, 2023
A Python, Flask login system

Python Login System This is a basic login + authenticason system for flask using Flask_Login and Flask_SQLAlchemy Get started on your own To use this

MrShoe 0 Feb 02, 2022
SQLAlchemy database migrations for Flask applications using Alembic

Flask-Migrate Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations

Miguel Grinberg 2.2k Dec 28, 2022
Flask-template - A simple template for make an flask api

flask-template By GaGoU :3 a simple template for make an flask api notes: you ca

GaGoU 2 Feb 17, 2022
A flask app that turn image into ASCII art

ASCII art A flask app that turn image into ASCII art. This app has been deployed to https://motmaytinh.herokuapp.com Getting Started These instruction

Trần Ngọc Quý 1 Jan 13, 2022
Harmony, a discord clone, allows users to chat with other users in real time via servers, channels, and direct messages

Harmony, a discord clone, allows users to chat with other users in real time via servers, channels, and direct messages

Seth Holland 3 Feb 03, 2022
Flask Boilerplate - Paper Kit Design | AppSeed

Flask Paper Kit Open-Source Web App coded in Flask Framework - Provided by AppSeed Web App Generator. App Features: SQLite database SQLAlchemy ORM Ses

App Generator 86 Nov 29, 2021
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
Guitar tabs web app for guitar fans, powered by Python/Flask

Guitar123 version 0.8.5 Guitar tabs web app for guitar fans, powered by Python/Flask Features Guitar tabs search and browse Easy to use for end user a

lowrain 48 Dec 27, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
Flask-Diamond is a batteries-included Flask framework.

Flask-Diamond Flask-Diamond is a batteries-included Python Flask framework, sortof like Django but radically decomposable. Flask-Diamond offers some o

Diamond Methods 173 Dec 22, 2022
Analytics snippets generator extension for the Flask framework.

Flask-Analytics Flask Analytics is an extension for Flask which generates analytics snippets for inclusion in templates. Installation $ pip install Fl

Mihir 80 Nov 30, 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
A team blog based on Flask

A team blog based on Flask This project isn't supported at the moment, please see a newer pypress-tornado Thanks for flask_website and newsmeme at [ht

老秋 549 Nov 10, 2022
Flask Project Template A full feature Flask project template.

Flask Project Template A full feature Flask project template. See also Python-Project-Template for a lean, low dependency Python app. HOW TO USE THIS

Bruno Rocha 96 Dec 23, 2022