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 (..) module Configuration exposing (..)
import Analytics
import Dict exposing (Dict) import Dict exposing (Dict)
...@@ -14,6 +15,11 @@ appUrl = ...@@ -14,6 +15,11 @@ appUrl =
"http://localhost:3011/" "http://localhost:3011/"
piwik : Maybe Analytics.PiwikConfiguration
piwik =
Nothing
twitterName : String twitterName : String
twitterName = twitterName =
"@OGPToolbox" "@OGPToolbox"
......
port module Ports exposing (..) port module Ports exposing (..)
import Analytics
import Configuration import Configuration
import Types exposing (DocumentMetadata, PopularTag, User) import Types exposing (DocumentMetadata, PopularTag, User)
import Urls import Urls
...@@ -77,6 +78,13 @@ port fileContentRead : (ImagePortData -> msg) -> Sub msg ...@@ -77,6 +78,13 @@ port fileContentRead : (ImagePortData -> msg) -> Sub msg
-- PIWIK
port initPiwikAnalytics : Analytics.PiwikConfiguration -> Cmd msg
-- SHARERS -- SHARERS
......
...@@ -9,6 +9,7 @@ import Collections.Item.State ...@@ -9,6 +9,7 @@ import Collections.Item.State
import Collections.Edit.State import Collections.Edit.State
import Collections.Index.State import Collections.Index.State
import Collections.Index.Types import Collections.Index.Types
import Configuration
import Decoders import Decoders
import Dict exposing (Dict) import Dict exposing (Dict)
import Dom.Scroll import Dom.Scroll
...@@ -30,32 +31,41 @@ import Urls ...@@ -30,32 +31,41 @@ import Urls
init : Flags -> Navigation.Location -> ( Model, Cmd Msg ) init : Flags -> Navigation.Location -> ( Model, Cmd Msg )
init flags location = init flags location =
{ authentication = let
Json.Decode.decodeValue Decoders.userDecoder flags.authentication ( model, cmd ) =
|> Result.toMaybe { authentication =
, authenticatorCancelMsg = Nothing Json.Decode.decodeValue Decoders.userDecoder flags.authentication
, authenticatorCompletionMsg = Nothing |> Result.toMaybe
, authenticatorModel = Authenticator.State.init , authenticatorCancelMsg = Nothing
, authenticatorRoute = Nothing , authenticatorCompletionMsg = Nothing
, cardModel = Cards.Item.State.init , authenticatorModel = Authenticator.State.init
, cardNewModel = Cards.New.State.init , authenticatorRoute = Nothing
, collectionEditModel = Collections.Edit.State.init , cardModel = Cards.Item.State.init
, collectionModel = Collections.Item.State.init , cardNewModel = Cards.New.State.init
, collectionsModel = Collections.Index.State.init , collectionEditModel = Collections.Edit.State.init
, displayNewCardModal = False , collectionModel = Collections.Item.State.init
, location = location , collectionsModel = Collections.Index.State.init
, navigatorLanguage = , displayNewCardModal = False
flags.language , location = location
|> String.left 2 , navigatorLanguage =
|> String.toLower flags.language
|> I18n.languageFromIso639_1 |> String.left 2
, route = I18nRouteWithoutLanguage "" |> String.toLower
, searchInputValue = "" |> I18n.languageFromIso639_1
, searchModel = Search.State.init , route = I18nRouteWithoutLanguage ""
, signOutMsg = Nothing , searchInputValue = ""
, userProfileModel = UserProfile.State.init , searchModel = Search.State.init
} , signOutMsg = Nothing
|> update (LocationChanged 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 navigate : String -> String -> Cmd msg
......
...@@ -75,6 +75,21 @@ main.ports.fileSelected.subscribe(function (id) { ...@@ -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) { main.ports.mountd3bubbles.subscribe(function (data) {
// Remove previous D3 bubbles instances if present in the DOM. // Remove previous D3 bubbles instances if present in the DOM.
Array.prototype.forEach.call( document.querySelectorAll("svg.D3Bubbles"), function (node) { 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