Git Product home page Git Product logo

trackingjs's Introduction

---> Deprecated

Development

Step 1 - start

start server

grunt serve

Step 2 - development

do it exactly

Step 3 - create example

create a example

Step 4 - testing

jshint

grunt jshint

http://localhost:3000/tests/ua.html
http://localhost:3000/tests/ecommerce.html
http://localhost:3000/tests/core.html

Step 5 - Doc

create Documentation

#USAGE

Installation

$ bower install tracking-js

Include jQuery tracking.js and adapter/ua.js scripts: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="/adapter/ua.js"></script> <script src="/tracking.js"></script>

##Properties ###namespace: Default: (string) namespace
namespace for the tracking code. Need it for multiTrack

###type Default: (string) ua
adapter type (ua = Universal Analytics

###analyticsCode Default: (string)
for the ua adapter we need the google analytics code

###url Default: (string) auto
url of your page or auto

###pageview Default: (boolean) true
send pageview on page loaded

###dataName Default: (string) trackingjs
is for the event register we can set on the default on data-trackingjs=""

###debug Default: (boolean) false
view debug messages

###anonymizeIp Default: (boolean) false
(boolean) false | on true the ip will be anonymous

###eventBundles:
Default: (array)
(array) | name of the bundles

###set Default: (object) {}
(object) {} | visit: https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference#set

##Using

Default tracking

First register a new trackingJS instance:
var options = {
    type: 'ua',
    namespace: 'myNamespace',
    analyticsCode: 'UA-xxxxxxxx-1',
    url: 'auto',
    pageview: false,
    anonymizeIp: true,
    debug: false
}; //view properties
var trackingJS = new trackingJS(options);
sending pageview
trackingJS.pageview('/page-url', 'Page title', function() {
    console.log('pageview sended');
});
sending event
trackingJS.event('category', 'action', 'label', 1, function() {
    console.log('event sended');
});
register event

use 'data-trackingjs' attribut to register an event. 'event' (required) 'category' (required) 'action' (required) 'label' (optional) 'value' (optional)

<a href="#" data-trackingjs='{"event":"click", "category":"category", "action":"action", "label":"label", "value":"1"}'>click to send event</a>

####### use in twig

{% set trackOption = {
            'event': 'click',
            'category': 'category name',
            'action': 'action name',
            'label': 'label name',
            'value': 1 //optional
        }
%}
<a href="#" data-trackingjs='{{ trackOption|json_encode()|e }}'>click to send event</a>

to update event data use the jQuery .data method and sen them an javascript object like:

var newEventData = {
    event: 'click',
    category: 'category',
    action: 'action',
    label: 'label',
    value: 1 //optional
};

$('a').attr('data-trackingjs', JSON.stringify(newEventData));

to update the event type (e.g. from click to mouseover) or initialize ajax loaded content use the updateEvents command

var newEventData = {
    event: 'mouseover',
    category: 'category',
    action: 'action',
    label: 'label',
    value: 1 //optional
};


$('a').attr('data-trackingjs', JSON.stringify(newEventData));

trackingJS.updateEvents();

eCommerce

register a new eCommerce Tracking instance
    var ecTracking = trackingJS.registerEcommerce();
add transaction datas
    ecTracking.setId(1);
    ecTracking.setAffiliation('test store');
    ecTracking.setShipping(5);
    ecTracking.setTax(20);
add a item
    ecTracking.addItem({
        id: '1',
        name: 'Product 1',
        sku: 'abc-1',
        category: 'Products category',
        price: 11.00,
        quantity: 1
    });
at least you must send the eCommerce event
    ecTracking.send();

Bundles

Include eventBundle/bundleName.js script:

    <script src="/scripts/eventBundle/authBundle.js"></script>

Add the option with all bundles on the Construct

    eventBundles: ['auth', 'link', 'video']

-> use the bundle

multiTracking

Include multiTrack.js script:

    <script src="/scripts/multiTrack.js"></script>
Register your Tracking instances
    var trackingJSone = new trackingJS({
        namespace: 'one',
        type: 'ua',
        analyticsCode: 'UA-xxxxxxxx-1',
        url: 'auto',
        pageview: false
    });

    var trackingJStwo = new trackingJS({
        namespace: 'two',
        type: 'ua',
        analyticsCode: 'UA-xxxxxxxx-2',
        url: 'auto',
        pageview: false
    });

    multiTrackJS.register(trackingJSone);
    multiTrackJS.register(trackingJStwo);
send pageview
    multiTrackJS.pageview('test/multi', 'UA-xxxxxxxxx-1 and UA-xxxxxxxxx-2');
send event
    multiTrackJS.event('category1', 'action', 'label', 1);
its simple to use eCommerce Tracking on multiTrack
    var multiEcTrack = new multiTrackJS.registerEcommerce();
        multiEcTrack.setId(1);
        multiEcTrack.addItem({
            id: '1',
            name: 'Product 1',
            sku: 'xyz-1',
            category: 'Products Cat',
            price: 11,
            quantity: 1
        });

        multiEcTrack.addItem({
            id: '2',
            name: 'Product 2',
            sku: 'xyz-2',
            category: 'Products Cat',
            price: 22,
            quantity: 2
        });

        multiEcTrack.send();

trackingjs's People

Contributors

dominikmatt avatar leph24 avatar alexander-schranz avatar natterstefan avatar

Stargazers

Kevin Liu avatar Daniel Metzler avatar  avatar Markus Fink avatar

Watchers

Thomas Schedler avatar James Cloos avatar Cornelius Hansjakob avatar  avatar  avatar Daniel Metzler avatar

trackingjs's Issues

Alternative Debug Console

  • HTML & CSS Debug Console for non-coders instead of browser console
  • with basic buttons (show all events of page) and other stuff
  • pls make it repsonsive

Regards,
Stefan

check if link always have a tracking-event

please add to the linkHandler in linkBundle.js the following line to check if the link have a own tracking-definition (if (!$el.data('trackingjs')) {)

...
    var linkHandler = function(event) {
        var $el = $(event.currentTarget),
            href = $el.attr('href'),
            target = $el.attr('target'),
            external = new RegExp('^((f|ht)tps?:)?//(?!' + location.host + ')');

        // check if link always have a tracking-definition
        if (!$el.data('trackingjs')) {
            // phone
            if(/tel:/.test(href)) {
                this.tracking.event(
...

opt-out

<script> 
// Set to the same value as the web property used on the site
var gaProperty = 'UA-XXXX-Y';

// Disable tracking if the opt-out cookie exists.
var disableStr = 'ga-disable-' + gaProperty;
if (document.cookie.indexOf(disableStr + '=true') > -1) {
  window[disableStr] = true;
}

// Opt-out function
function gaOptout() {
  document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
  window[disableStr] = true;
}
</script>

Register Event fix

var newEventData = {
event: 'click',
category: 'category',
action: 'action',
label: 'label',
value: 1
};

$('a').data('trackingjs', newEventData);

has to be changed to:

$('a').attr('data-trackingjs', JSON.stringify(newEventData));

Onepage Tracking (Bundle)

  • Onepage Tracking Features; i.e. if # changes
  • Scroll Depth: how many % of the one page has the visitor seen

Regards,
Stefan

eCommerce currency not implemented

implement eCommerce currency
ga('ecommerce:addTransaction', {
'id': '1234',
'affiliation': 'Acme Clothing',
'revenue': '11.99',
'shipping': '5',
'tax': '1.29',
'currency': 'EUR' // local currency code.
});

Standard Event Implementation

Please include standard events like (note: $var represents a variable)

Download: Download // Download - $filetype // Download: $filname ($filetype)
Contact - Mail: Contact // Contact - Mail // Contact: $mailaddress
Contact - Tel: Contact // Contact - Tel // Contact: $telelephonenumber
External Link: Link // Link - External Link // External Link: $target
Social Media ($type = ie. share, follow ...): Social Media // Social Media - $type $network // Social Media: $type $network

If you have any questions, just ask.

Stefan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.