The source code is available in a private repository on Github, along with instructions for building/running the project locally. Please fork it from here: https://github.com/skyglobal/analytics/
<script src=//analytics.global.sky.com/1.4.8/analytics.js></script>
(this works over http
or https
).
If your project uses RequireJS, Click here to see a requireJS example.
analytics.setup({
site: 'global',
section: 'skyglobal/analytics/demo',
account: 'bskybdemodev' //insert correct account here depending on your environment
});
analytics.trackPage();
At the moment, you will need to call setup again with the new properties and then trackpage (although probably only section will have changed). We hope to change this soon.
There are a few things you get for free. These are:
sessionCamID
variable gets set if the page has SessionCam.
sessionCamID
variable gets set if the page has SessionCam.
masthead
variable gets tracked automatically when a link is clicked within the masthead.
To get you config correct, please get the details for your project from implementation@bskyb.com
. The following shows the options:
sky/portal/
prefix. You can either add debug:true
or execute
analytics.debug([true|false]);
.
Click here to see debug on load in action.
Try turning debug on and debug off then clicking the following link: Sky.com Homepage
Please note, when debug is on, the user is not taken to the link and tracking information is not sent. This behaviour is intentional and allows the user to check the tracking in the console.
analytics.setup({
page: document.title,
site: 'global',
section: 'skyglobal/analytics/demo',
account: 'bskybdemodev',
loadVariables: {'videoTitle':'My Home Video', 'externalSearchTerm':'thrill rides'},
loadEvents: ['activateComplete'],
customEvents: [
{'magic_happened': {event: 101, onPageLoad:true}}
],
customVariables: [
{'drink': {'eVar': 72}},
],
debug: false
});
Click here to see this custom config in action.
Pages are commonly split up in the following areas: Modules, Pods and other. You may also want to track Editorial-Themes or the Context along with the clicked text1.
Add the following data
attributes to the relevant containers within your page.
When an element is clicked, the JS will traverse up the DOM looking for these attributes.
data-tracking-module=carousel
data-tracking-pod=slide2
data-tracking-other=subnav-text
data-tracking-theme=friends-and-family
data-tracking-context=bond-11
or data-tracking-context-id=search-box
data-tracking-label=bond-remote-record
data-tracking-context-id
.
data-tracking-search=weather data-tracking-context-id=search-box
data-tracking=false
1
By default we automatically track the text
that is clicked along with the site
name.
In order of priority, we track text
by looking for the attributes: 'data-tracking-label', 'alt', 'value' and 'name'. If these are not found we will use the elements inner-text.
a
' tags will be tracked automatically
HTML
<a href='#' >link</a>
Javascript
none
button
' tags will be tracked automatically
HTML
<button>Button</button>
Javascript
none
input
' tags with type=submit
will be tracked automatically
HTML
<input type="submit" value="Submit"/>
Javascript
none
data-tracking
' needs to be added to any other tags you wish to track
HTML
<span data-tracking >Span</span>
Javascript
none
data-tracking-label
' you can change the text that is tracked.
HTML
<a data-tracking-label='label-text' href="#">Link</a>
Javascript
none
data-tracking-context
' you can differentiate between 2 CTA's that do different things.HTML
<a href="#" data-tracking-context='Sky News'>Record</a>
<a href="#" data-tracking-context='Sky Sports'>Record</a>
Javascript
none
data-tracking-pod
' and 'data-tracking-module
' you can provide more information about where in the page links are located.
HTML
<div data-tracking-module=testing>
<div data-tracking-pod=pod-1>
<a href="#!" >pod 1</a>
</div>
<div data-tracking-pod=pod-2>
<a href="#!">pod 2</a>
</div>
</div>
Javascript
none
data-tracking-other
' can be used to track any other useful info, i.e. when navigation gets past 2 levels.data-tracking-theme
' can be used to allow editors monitor page elements that are related over time.
HTML
<div data-tracking-module=testing>
<div data-tracking-other=js-off-link>
<a href="#!" >Other info</a>
</div>
<div data-tracking-theme=editorial-promo-winter>
<a href="#!">Themes</a>
</div>
</div>
Javascript
none
data-tracking=false
' you can stop any element from tracked automatically.
HTML
<a data-tracking=false href="#">link</a>
<button class="btn" data-tracking="false" id="button-not-tracked" >button</button>
<input type=submit data-tracking="false" value="Submit" id="submit-not-tracked" />
Javascript
none
There are a number of variables that are standard within omniture, which means you can use them without mapping them to an eVar
or prop
id.
A list of standard variables can be found here.
When initialising, you will need to add customVariables
array which may contain some options:
Array
.Array
onPageLoad
is set
The name of this object needs to match an HTML element using the attribute
data-tracking-variable
.
Optionally, data-tracking-value
can also be used to send an alternate value to Omniture,
otherwise the text clicked will be tracked.
data-tracking-variable
.
HTML
<button data-tracking-variable='videoTitle' data-tracking-value="My Videos" >Send Standard Variable</button>
Javascript
none
loadVariables
in the config.
HTML
<button data-tracking-variable='videoTitle' data-tracking-value="My Videos" >Send Standard Variable</button>
Javascript
analytics.trackPage({
site: 'global',
section: 'skyglobal/analytics',
account: 'bskybdemodev',
loadVariables: {'videoTitle':'My Home Video', 'externalSearchTerm':'thrill rides'}
});
drink
and setting the value to the content of a text box.
HTML
<label for='input_field'>What is your favourite drink?</label>
<input id='input_field' name='input_field' type='text' />
<button data-tracking-variable='drink' data-tracking-value="" class='btn primary-cta'>Submit</button>
Javascript
analytics.trackPage({
...
customVariables: [
{'colour': {eVar: 72 }}
]
});
<script>//script to update data-tracking-value attribute
$('[data-tracking-variable=drink]').attr('data-tracking-value',$('#input_field').val());
</script>
briansCat
on page load as a prop
.
HTML
none
Javascript
analytics.trackPage({
...
customVariables: [
{'briansCat': { prop: 66, value:'is great', onPageLoad:true }}
]
});
briansCat
on click as a eVar
and prop
.
HTML
<button data-tracking-variable='briansEVarAndPropCat' >Send Custom eVar and Prop&;lt;/button>
Javascript
analytics.trackPage({
...
customVariables: [
{'briansEVarAndPropCat': { eVar: 11, prop: 66, value:'is great'}}
]
});
how_about_pina_coladas
and setting it to the selected radio button
HTML
<label>Do you like Pina Coldas?</label>
<input id='radio_yes' name='radio_field' type='radio' value='yes_to_pinas'/>
<label for='radio_yes'>Yes</label>
<input id='radio_no' name='radio_field' type='radio' value='no_to_pinas'/>
<label for='radio_no'>No</label>
<button data-tracking-variable='how_about_pina_coladas' class='btn primary-cta'>Submit</button>
Javascript
analytics.trackPage({
...
customVariables: [
{'how_about_pina_coladas': {eVar: 73 }}
]
});
<script>//script to update data-tracking-value attribute
$('[data-tracking-variable=how_about_pina_coladas]').attr(
'data-tracking-value',
$('input[name=radio_field]:checked').val()
);
</script>
colour
and setting it to the value of the button clicked
HTML
<button data-tracking-variable="colour">Blue</button>
<button data-tracking-variable="colour">Gray</button>
Javascript
analytics.trackPage({
...
customVariables: [
{'colour': {eVar: 71 }}
]
});
onPageLoad: true
in the config.HTML
none
Javascript
var config = {
...
customVariables: [
{'how_about_pina_coladas': {eVar: 73, value:'my val on load', onPageLoad: true}}
]
};
analytics.trackPage(config);
list
and set the value to an Array
.HTML
none
Javascript
var config = {
...
customVariables: [
{'myListOfStuff': {list: 1, value:['val1','my second','final value'], onPageLoad: true}}
]
};
analytics.trackPage(config);
list
and update the HTML.
If you set the value within the HTML, the list must be piped
deliminatedHTML
<button data-tracking-variable="customer-offers">List Variable on click</button>
Javascript
var config = {
...
customVariables: [
{'customer-offers': {list: 2}}
]
};
analytics.trackPage(config);
hier
and set the value to an Array
.HTML
none
Javascript
var config = {
...
customVariables: [
{'myHierarchyOfStuff': {hier: 2, value:['h1','second h','final hier'], onPageLoad: true}}
]
};
analytics.trackPage(config);
hier
and update the HTML.
If you set the value within the HTML, the list must be piped
deliminated.HTML
<button data-tracking-variable="my-heirarchy">Hierarchy Variable on click</button>
Javascript
var config = {
...
customVariables: [
{'my-heirarchy': {hier: 2}}
]
};
analytics.trackPage(config);
There are a number of events that are standard within omniture, which means you can use them without mapping them to an event
id.
A list of standard events can be found here within eventsMap
.
An array of 'Custom Events' can be added to the analytics config
on initialisation..
The Custom Events array will contain an object with the following options:
data-tracking-event
.
HTML
<button data-tracking-variable='liveChat' >Send Standard Event</button>
<button data-tracking-variable='orderConfirmation' >Send orderConfirmation Event</button>
Javascript
none
loadEvents
in the config.
HTML
<button data-tracking-variable='liveChat'>Send Standard Event on load</button>
<button data-tracking-variable='productSelection'>Send productSelection Event on load</button>
Javascript
analytics.trackPage({
site: 'global',
section: 'skyglobal/analytics',
account: 'bskybdemodev',
loadEvents: ['liveChat']
});
data-tracking-event=eventName
to the relevant element.HTML
<a href='#' data-tracking-event='magic_happened'>Custom Event</a>
Javascript
var config = {
...
customEvents: [
{'magic_happened': {event: 101}}
]
};
analytics.trackPage(config);
onPageLoad: true
in the config.HTML
none
Javascript
var config = {
...
customEvents: [
{'magic_happened': {event: 101, onPageLoad: true}}
]
};
analytics.trackPage(config);
serial
in the config.HTML
none
Javascript
var config = {
...
customEvents: [
{'serial-event': {event: 666, serial: 'devil12345'}}
]
};
analytics.trackPage(config);
To track media on the page you will need to specify the media to track individually. This includes using tracking function every time that media changes.
When calling .trackMedia
you will need to pass the following config options:
video
' tags will be tracked
HTML
<video controls> <'video>
Javascript
analytics.trackMedia({
videoElement: document.getElementById('pooh-video'),
category:"skymovies",
mediaUrl:"http://static.video.sky.com/skymovies/2014/02/73756/73756-576p_2000K_H264.mp4",
videoTitle:"Winnie the Pooh: Trailer",
type:"video",
guid:"clip-0044tyky",
videoFormat:"576p|2000k|video/mp4",
provider:"skyvideolibrary"
});
To track searchType
and searchTerms
, you need to add the following into your HTML:
Once the search is complete and results have been returned, the above info should be sent with trackPage
along with how many results we're returned.
Using 'data-tracking-search
' with 'data-tracking-context-id
' will activate the Omniture Search Variables.
If you do not have a data-tracking-other
set, then either 'click
' or 'keydown
' will also be tracked.
HTML
<input id="search" type="text" placeholder="Postcode or town">
<button data-tracking-search="weather" data-tracking-context-id="search">Search</button>
Javascript
data-tracking-other
already defined, it will not get over-written.
HTML
<input id="search" type="text" placeholder="Postcode or town">
<button data-tracking-search="weather" data-tracking-context-id="search">Search</button>
Javascript
trackPage
with loadVariables: searchResults, searchType and searchTerm1.
HTML
none
Javascript
analytics.trackPage({
site: 'global',
section: 'skyglobal/analytics/results',
account: 'bskybglobaldev',
loadVariables: { 'searchResults': 1, 'searchType':'weather', 'searchTerm': 'london' }
});
1When searchResults
variable is set, the searchResults
event will be sent automatically.
Tracking an error is as easy 1, 2, 404. You can either send an error on trackPage
or via JS.
analytics.trackError
function.
HTML
none
Javascript
analytics.trackError('myCustomError i.e. no-package-found');
loadVariables
in the trackPage config.
HTML
none
Javascript
SITECAT_CONFIG = {
site: 'global',
section: 'skyglobal/analytics/debug',
headline: '',
contentType: 'demo',
contentId: '',
account: 'bskybglobaldev',
loadVariables: { errors: 'nnn-service-down' }
};
analytics.trackPage(SITECAT_CONFIG);
loadVariables
in the trackPage config.
HTML
none
Javascript
SITECAT_CONFIG = {
page: '404',
site: 'global',
section: 'skyglobal/analytics/404',
headline: '',
contentType: '404',
contentId: '',
account: 'bskybglobaldev',
loadVariables: { '404Page': 'errorPage' }
};
analytics.trackPage(SITECAT_CONFIG);
If you have set trackClicks: false
in the config you will need to manually set up the link track binding.
You will also have to manually trigger analytics.trackPage
for 'single-page apps'.
This is useful for 'backbone' apps for example.
config
to, and call the trackPage
function.
HTML
none
Javascript
analytics.trackPage(config);
data-tracking=false
attribute exists.
HTML
<span id='trackingOff'>tracked with js</span>
Javascript
$('#trackingOff').trigger('analytics.track');
analytics.trackClick
manually
HTML
<span id='manualBind'>tracked with js</span>
Javascript
$(document).on('click', '#manualBind, manualBindA', analytics.trackClick);
You can send events/variables to omniture during the life of a page using analytics.trackAdHoc
.
setup
and call the trackAdHoc
function.
HTML
none
Javascript
analytics.setup({
site: 'global',
section: 'skyglobal/analytics/demo',
account: 'bskybdemodev',
contentType: 'analytics',
customVariables: [
{'briansCat': {'eVar': 66}}
],
customEvents: [
{'myAdHocEvent': {'event': 69} }
]
});
analytics.trackAdHoc(
{'briansCat': 'is still great'},
{'testAndTarget': 'is poo'},
'myAdHocEvent'
);
config
, track page view and then call the trackAdHoc
function.
HTML
none
Javascript
analytics.setup({
site: 'global',
section: 'skyglobal/analytics/demo',
account: 'bskybdemodev',
contentType: 'analytics',
customVariables: [
{'briansCat': {'eVar': 66}}
],
customEvents: [
{'myAdHocEvent': {'event': 69} }
]
});
analytics.trackPage();
analytics.trackAdHoc(
{'briansCat': 'is still great'},
{'testAndTarget': 'is poo'},
'myAdHocEvent'
);