Commit 198a0b45 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add preliminary support for Piwik analytics.

parent 5f23897d
module Analytics exposing (..)
type alias PiwikConfiguration =
{ piwikDomain : String
, siteId : String
}
module Configuration exposing (..)
import Analytics
import Dict exposing (Dict)
......@@ -14,6 +15,11 @@ appUrl =
"http://localhost:3011/"
piwik : Maybe Analytics.PiwikConfiguration
piwik =
Nothing
twitterName : String
twitterName =
"@OGPToolbox"
......
port module Ports exposing (..)
import Analytics
import Configuration
import Types exposing (DocumentMetadata, PopularTag, User)
import Urls
......@@ -77,6 +78,13 @@ port fileContentRead : (ImagePortData -> msg) -> Sub msg
-- PIWIK
port initPiwikAnalytics : Analytics.PiwikConfiguration -> Cmd msg
-- SHARERS
......
......@@ -9,6 +9,7 @@ import Collections.Item.State
import Collections.Edit.State
import Collections.Index.State
import Collections.Index.Types
import Configuration
import Decoders
import Dict exposing (Dict)
import Dom.Scroll
......@@ -30,6 +31,8 @@ import Urls
init : Flags -> Navigation.Location -> ( Model, Cmd Msg )
init flags location =
let
( model, cmd ) =
{ authentication =
Json.Decode.decodeValue Decoders.userDecoder flags.authentication
|> Result.toMaybe
......@@ -56,6 +59,13 @@ init flags location =
, userProfileModel = UserProfile.State.init
}
|> update (LocationChanged location)
in
case Configuration.piwik of
Just piwik ->
model ! [ cmd, Ports.initPiwikAnalytics piwik ]
Nothing ->
( model, cmd )
navigate : String -> String -> Cmd msg
......
......@@ -75,6 +75,21 @@ main.ports.fileSelected.subscribe(function (id) {
});
main.ports.initPiwikAnalytics.subscribe(function (configuration) {
var _paq = _paq || [];
// Tracker methods like "setCustomDimension" should be called before "trackPageView".
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//"+configuration.piwikDomain+"/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', configuration.siteId]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
});
main.ports.mountd3bubbles.subscribe(function (data) {
// Remove previous D3 bubbles instances if present in the DOM.
Array.prototype.forEach.call( document.querySelectorAll("svg.D3Bubbles"), function (node) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment