-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbookmarklet.html
169 lines (147 loc) · 7.96 KB
/
bookmarklet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tracking Codes</title>
<link type="text/css" rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap-theme.min.css">
<link type="text/css" rel="stylesheet" href="http://getbootstrap.com/examples/theme/theme.css">
<style>
.show-table {
min-width: 450px;
padding: 5px;
}
.show-table td {}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body role="document">
<!-- Fixed navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand" href="#">Social Tools</span>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">SHOWS <b class="caret"></b></a>
<ul class="dropdown-menu show-table">
<li>
<table class="table">
<tr>
<td><a href="#show1">show1</a></td>
<td><a href="#show2">show2</a></td>
<td><a href="#show3">show3</a></td>
<td><a href="#show4">show4</a></td>
</tr><tr>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container theme-showcase" role="main">
<div class="page-header">
<h1>Tracking Codes</h1>
<p class="lead">Google Analytics For Your Pieces</p>
<!-- This is the Underscore.js template for each of our links. -->
<!-- I didn't HAVE to make this a template. But I wanted to show -->
<!-- how you might do this if you were doing it by our standards. -->
<!-- Inside this script tag, you can write HTML with some little things, -->
<!-- <%= foo %> means to print the Javascript variable "foo". -->
<!-- <% %> means you would like to write some Javascript to be evaluated but not printed. -->
<!-- So if you wanted to print the name of a network, you'd do: -->
<!-- <%= network.network_name %> -->
<!-- If you wanted to do a for loop inside the template, you'd do: -->
<!-- <% _.each(NETWORKS, function(i, network){ console.log(network) }); %> -->
<!-- This is useful for many reasons. We can talk about those later. -->
<script type="text/html" class="template-link">
<li><a href="javascript:<%= javascript_string %>">
<%= network.network_name %>
</a></li>
</script>
<!-- Include jQuery and Underscore.js -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
<script type="text/javascript" src="http://underscorejs.org/underscore-min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<!-- This is the meat of our script. Notice it goes at the bottom. -->
<script type="text/javascript">
// Let's define a pair of global variables as constants.
// This will be your networks and shows.
// Note that both of these are just arrays of Javascript objects.
NETWORKS = [
{
network_name: "NAME OF SOCIAL NETWORK",
network_param: "?utm_medium=TRACKINGCODEFORSOCIALNETWORK"
}, {
network_name: "NAME OF A DIFFERENT SOCIAL NETWORK",
network_param: "?utm_medium=TRACKINGCODEFORSOCIALNETWORK2"
},
];
SHOWS = [
{
show_slug: "SHOW-NAME",
show_name: "SHOWNAMECONDENSED",
show_param: "TRACKING_CODE_FOR_SHOW"
},
];
// Now, let's do our actual scripting.
// I've enclosed this in a $(document).ready() function so as not to execute before
// the DOM has finished rendering. That's not important for this app so much but it's
// definitely a best practice.
$(document).ready(function(){
// Set up a variable where the nav's ul is.
var $nav_el = $('.navbar-collapse ul');
// Okay, now let's loop over the shows.
// For each show, let's append a link to the nav (for navigating) and then also
// append some HTML to the body for the actual bookmarklets and such.
$.each(SHOWS, function(i, show) {
// Let's make a div with the id of our show's slug.
$('div.theme-showcase').append('<div class="row" id="' + show.show_slug + '"><ul></ul></div>');
// And then let's cache the element for this thing.
var $show_el = $('#' + show.show_slug);
var $show_list_el = $('#' + show.show_slug + ' ul');
// Now, let's append an H2 to that element. We want this to look stylish.
$show_el.prepend('<h2>' + show.show_name + '</h2>');
// Next, let's loop over all the social networks and add a bookmarklet to
// this show for each one.
$.each(NETWORKS, function(i, network){
// Since we're using a template for the actual bookmarklet, let's parse it.
var parsed_template = _.template($('script.template-link').html());
// Make our bookmarklet as a string. This is the actual Javascript that the
// browser will execute as a bookmarklet.
var javascript_string = "var bookmarklet=function(){var show='" + show.show_param + "';work='" + network.network_param + "';var today=new Date();var dd=today.getDate();var mm=today.getMonth()+1;var yyyy=today.getFullYear();if(dd<10){dd='0'+dd}if(mm<10){mm='0'+mm}today=mm+dd+yyyy;window.location=(String(window.location).split('?')[0]+work+show+'&utm_content='+today);};bookmarklet();";
// Next, let's compile our template with some variables we need to make the
// template work. We need to know the network, the show and that long
// Javascript string that is the bookmarklet.
var compiled_template = parsed_template({
'javascript_string': javascript_string,
'network': network,
'show': show
});
// Finally, we need to append that compiled template to the DOM.
// Let's stick it inside of that show element we defined earlier.
$show_list_el.append(compiled_template);
});
});
});
</script>
</body>
</html>