I am currently using SlideDeck and reporting the viewed slide number to be reported in Google Analytics. What I’m wondering (and honestly have no idea if possible) is whether if the slide deck API reports a specific number, I can assign a label/text to it?
The code I’m using is:
$(document).ready(function() {
$('#nextSlide').click(function() {
$('.slidedeck').slidedeck().next({
before: function(deck){
// do nothing
},
complete: function(deck){
var slideNumber = deck.current != null ? deck.current + ' - ' : '';
_gaq.push(['_trackEvent', 'slidedeck', 'viewed slides', slideNumber + 'slide number']);
}
});
});
});
This successfully reports the following to Google Analytics:
‘slidedeck’ (category), ‘viewed slides’ (label), ‘1 – slide number’ (value, assuming slide 1 is being shown).
What I want to do is assign a name to the result 1, 2, 3 etc..
So in my head (and this is completely not the code as I have no clue how to approach this, but to demonstrate the kind of result:
var slideNumber = deck.current != null ? deck.current + ' - ' : '';
if($(this).val() == '1'){ //function to report code as '1 - title example'}
});
if($(this).val() == '2'){ //function to report code as '2 - title example'}
});
So the GA event tracking code would be:
_gaq.push(['_trackEvent', 'slidedeck', 'viewed slides', slideNumber + 'was viewed']);
which submits an Event with the following label, assuming slide 1 is viewed:
‘slidedeck’ (category), ‘viewed slides’ (label), ‘1 – title example – was viewed’
I appreciate I’m being vague, and asking a lot – but if anyone can even steer me in the right direction or point me to the functions I’d need to look into, that’d be awesome.
EDIT:
I’ve added this code to the script nnnnnn:
$(document).ready(function() {
var slideTitles = [ "Slide 0 title here",
"Slide 1 title here",
"Slide 2 title here"
];
$('#next').click(function() {
$('.slidedeck').slidedeck().next({
before: function(deck){
// do nothing
},
complete: function(deck){
var slideNumber = deck.current != null ? deck.current + ' - ' : '';
_gaq.push(['_trackEvent', 'slidedeck', 'viewed slides', slideTitles[slideNumber] + 'was viewed']);
}
});
});
But I get the following Event Label in Google Analytics: ‘undefinedwas viewed’.
What I don’t get (as I’m new to jQuery!) is how the response from:
complete: function(deck){
var slideNumber = deck.current != null ? deck.current + ' - ' : '';
binds to the array titles?
the deck.current is an API response from the slidedeck plugin, just giving the numeric value of the currently viewed slide.
Sorry to be a pain!
You can put the titles in an array where the array indexes are (obviously) the slide numbers:
(If there’s no slide 0 just put an empty string as a placeholder so that the other indexes correspond to the right titles.)
Then in your existing code given a
slideNumberjust sayslideTitles[slideNumber]to get the corresponding title.