This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
/
howto-5.html
127 lines (110 loc) · 3.61 KB
/
howto-5.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
<!DOCTYPE HTML>
<html>
<head>
<title>Boomerang Howto #5: Request/page tagging</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../boomerang-docs.css">
</head>
<body>
<span style="float:right;"><a href="../">All Docs</a> | <a href="index.html">Index</a></span>
<h1>Boomerang Howto #5: Request/page tagging</h1>
<p>
See <a href="../use-cases.html#uc-5">use case #5</a> for a description of this requirement.
</p>
<p>
There will be several occassions when you need to add more information to the beacon that's sent
back to the server. For example, you may want to tag the beacon with a <code>page_id</code> or
you may want to do A/B testing and tag the beacon with a parameter specifying which bucket this
beacon is for. You can achieve all this using the <code>BOOMR.addVar()</code> method.
</p>
<p>
Before you use this method, remember that each plugin adds its own parameters and you shouldn't
overwrite these with your own values. See <a href="howto-0.html">Howto #0</a> for a list of
parameters set by boomerang's built-in plugins. Other plugins may add their own parameters,
consult the documentation of the plugin to find out what these are.
</p>
<pre>
BOOMR.addVar("page_id", 123);
</pre>
<p>
The parameter name must be a string. We recommend only using alphanumeric characters and underscores,
but you can really use anything you like. Parameter values may only be numbers or strings, ie,
something that you can put into a URL.
</p>
<p>
If you need to set multiple parameters, you can pass in an object instead:
</p>
<pre>
BOOMR.addVar({
"bucket": "test#1",
"page_id": 123
});
</pre>
<p>
Make sure you've included boomerang.js before calling <code>BOOMR.addVar()</code>.
</p>
<h2>The beacon</h2>
<p>
The beacon will include all variables that you add in the URL. Both keys and values will be
URI encoded. Your back end application will need to understand the passed in parameters.
</p>
<pre>
http://yoursite.com/path/to/beacon.php?<em>bucket=test%231</em>&<em>page_id=123</em>&t_done=.....
</pre>
<h2>Removing variables</h2>
<p>
You can also remove a parameter that you've added (or that a plugin has added) from the beacon.
To do this, call the <code>BOOMR.removeVar()</code> method. This method takes in a list of
name, and removes all of them from the parameter list. Any name that isn't in the parameter
list is ignored.
</p>
<pre>
<span class="comment">// don't send the stooges to the server </span>
BOOMR.removeVar("larry", "moe", "curly");
</pre>
<h2>Stopping the beacon</h2>
<p>
You can also this as a crude way to prevent the beacon from firing. Inside your <code>before_beacon</code>
event handler, simply remove all parameters.
</p>
<pre>
BOOMR.subscribe('before_beacon', function(o) {
var p_names = [], k;
if( "t_done" in o ) {
return;
}
<span class="comment">// t_done is not set, so don't beacon </span>
for(k in o) {
if(o.hasOwnProperty(k)) {
p_names.push(k);
}
}
<span class="comment">// removeVar accepts either a list or an array</span>
BOOMR.removeVar(p_names);
});
</pre>
<p class="perma-link">
The latest code and docs is available on <a href="http://github.com/lognormal/boomerang/">github.com/lognormal/boomerang</a>
</p>
<p id="results">
</p>
<script src="../../boomerang.js" type="text/javascript"></script>
<script src="howtos.js" type="text/javascript"></script>
<script type="text/javascript">
BOOMR.init({
user_ip: '10.0.0.1',
BW: {
base_url: '../../images/',
cookie: 'HOWTO-BA'
},
RT: {
cookie: 'HOWTO-RT'
}
}).
addVar({
"author": "bluesmoon",
"page_id": "howto-5"
});
</script>
</body>
</html>