@mate-academy/sourcebuster 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/UPGRADING.md ADDED
@@ -0,0 +1,293 @@
1
+ ## From 0.0.x to 1.0.0
2
+
3
+ I'm gonna walk you through the inline-HTML setup pattern, but keep in mind, that Sourcebuster `1.0.0` is available as `CommonJS` / `AMD` module, so you can `require` it as dependency as well.
4
+
5
+ ### Install
6
+
7
+ ```python
8
+ # from `npm`
9
+ npm install --save sourcebuster
10
+
11
+ # or `bower`
12
+ bower install --save sourcebuster
13
+ ```
14
+
15
+ Or you can [download this repo](https://github.com/alexfedoseev/sourcebuster-js/archive/master.zip) and use `sourcebuster.min.js` from `/dist` folder.
16
+
17
+ ### Setup
18
+
19
+ Place inside the `<head>` tag:
20
+
21
+ ```html
22
+ <script src="/path/to/sourcebuster.min.js"></script>
23
+ ```
24
+
25
+ Unlike `0.0.x`, in `1.0.0` this line will do nothing (I mean no cookies will be set) except it will make available Sourcebuster object — `sbjs`.
26
+
27
+ This object has just 2 methods: `init` and `get`. Basically first one is `setter`, and the second one is `getter`.
28
+
29
+ So, lets initialize it:
30
+
31
+ ```html
32
+ <script src="/path/to/sourcebuster.min.js"></script>
33
+ <script>
34
+
35
+ sbjs.init();
36
+
37
+ </script>
38
+ ```
39
+
40
+ This will:
41
+
42
+ - set all the cookies
43
+ - give you the data (through the second method `sbjs.get`)
44
+
45
+ ### Configure
46
+
47
+ `sbjs.init` accepts one argument: object with the settings. It's optional and usually it will be something like this:
48
+
49
+ ```javascript
50
+ sbjs.init({
51
+ domain: 'alexfedoseev.com',
52
+ lifetime: 3,
53
+ callback: doSmth
54
+ });
55
+ ```
56
+
57
+ Now I'll show you the whole list of configurable options. The short description is provided in comments. Some critical changes explained in this guide. The rest is explained in the documentation.
58
+
59
+ ```javascript
60
+ sbjs.init({
61
+
62
+ // Set custom expiration period for cookies in months
63
+ // 6 months is default
64
+ lifetime: 6,
65
+
66
+ // Set custom session length in minutes (no changes since 0.0.x)
67
+ // 30 minutes is default
68
+ session_length: 30,
69
+
70
+ // Set domain name in cookies
71
+ // Behaviour is changed! Detailed explanation below
72
+ domain: {
73
+ host: 'alexfedoseev.com',
74
+ isolate: false
75
+ },
76
+
77
+ // Set custom referrals (no changes since 0.0.x)
78
+ // This is an array of objects
79
+ referrals: [
80
+ {
81
+ host: 't.co', // This is host from Twitter's `http referer`
82
+ medium: 'social', // This is custom `utm_medium`, you can drop it and it'll be `referral`
83
+ display: 'twitter.com' // And this is how you'll see it in the result data
84
+ },
85
+ {
86
+ host: 'plus.url.google.com',
87
+ display: 'plus.google.com'
88
+ }
89
+ ],
90
+
91
+ // Set custom organics (no changes since 0.0.x)
92
+ // This is an array of objects
93
+ organics: [
94
+ {
95
+ host: 'bing.com',
96
+ param: 'q',
97
+ display: 'bing'
98
+ }
99
+ ],
100
+
101
+ // Set `utm_source` & `utm_medium` values for `typein` traffic
102
+ // Defaults are changed, now it's `(direct)` & `(none)`, detailed explanation below
103
+ typein_attributes: {
104
+ source: '(direct)',
105
+ medium: '(none)'
106
+ },
107
+
108
+ // Set time zone
109
+ // Default behaviour is changed, detailed explanation below
110
+ timezone_offset: 3,
111
+
112
+ // Set custom `utm_campaign` param (no changes since 0.0.x)
113
+ campaign_param: 'my_adwords_campaign',
114
+
115
+ // Set user ip (no changes since 0.0.x)
116
+ user_ip: '192.168.1.1',
117
+
118
+ // Set promocode (no changes since 0.0.x)
119
+ // Default range is [100000..999999]
120
+ promocode: {
121
+ min: 100000,
122
+ max: 999999
123
+ },
124
+
125
+ // Set callback-function,
126
+ // It will be executed right after `sbjs` cookies will be set
127
+ // Detailed explanation below
128
+ callback: doSmth
129
+ });
130
+ ```
131
+
132
+ #### Highlights
133
+
134
+ ##### domain
135
+
136
+ ```javascript
137
+ // 0.0.x
138
+ _sbjs.push(['_setBaseHost', 'alexfedoseev.com']);
139
+
140
+
141
+ //1.0.0
142
+ domain: 'alexfedoseev.com'
143
+
144
+ // the same
145
+ domain: {
146
+ host: 'alexfedoseev.com',
147
+ isolate: false
148
+ }
149
+ ```
150
+
151
+ The main thing, that changed, is how the script handles **the absence** of this custom option. When no `BaseHost` was set, script's cookie was set **only for current host**. That is ok, if the site doesn't have subdomains to share traffic with and it **never will**.
152
+
153
+ But what's gonna happen if someday subdomains will occur? In `0.0.x` they won't get the cookies, it means they won't share the traffic, and visitors from main domain to subdomains will be considered as `referral`.
154
+
155
+ I changed this behaviour, so if the setting is absent, cookies will be set for **current domain and all its subdomains**.
156
+
157
+ However if you don't want to share the cookies — use `isolate: true`, to isolate this domain.
158
+
159
+ So, how to update: just pick suitable configuration and pass it to `init` method. Migration tool will do the rest. It's one-time migration, so chose wisely.
160
+
161
+ Lets see how to set this option in common cases.
162
+
163
+ **— You don't have subdomains, but someday maybe**
164
+
165
+ ```javascript
166
+ // just don't use this option or use this one
167
+ domain: 'your-domain.com'
168
+ ```
169
+
170
+ **— You don't have subdomains, and don't want to share cookies for some reason**
171
+
172
+ ```javascript
173
+ domain: {
174
+ host: 'your-domain.com',
175
+ isolate: true
176
+ }
177
+ ```
178
+
179
+ **— You have subdomains and want to share traffic between them**
180
+
181
+ ```javascript
182
+ // on all pages of domain and its subdomains
183
+ domain: 'your-domain.com'
184
+ ```
185
+
186
+ **— You have subdomains, but don't want to share traffic between them**
187
+ (so visits from domain to subdomains and vise versa will be considered as `referral`)
188
+
189
+ ```javascript
190
+ // on all pages of domain
191
+ domain: {
192
+ host: 'your-domain.com',
193
+ isolate: true
194
+ }
195
+
196
+ // and on all pages of subdomain
197
+ domain: 'sub.your-domain.com'
198
+
199
+ // or
200
+ domain: {
201
+ host: 'sub.your-domain.com',
202
+ isolate: false // or use `isolate: true` if you'd like to isolate it too
203
+ }
204
+ ```
205
+
206
+ Hope you've got the point. If you have any questions — check [documentation](README.md) for more detailed explanation or [post an issue](https://github.com/alexfedoseev/sourcebuster-js/issues/new).
207
+
208
+ After you'll roll out the `1.0.0` to production, visitor's old cookies will be updated to chosen setup. Again: it's one-time migration, so chose wisely.
209
+
210
+ **NB! Do not change `isolate` value after update. If you'll do — your visitors will get doubled cookies and bad things may happen.**
211
+
212
+ The option, that will give the ability to force-update cookies domain (if you need to change subdomains handling rules), is in my TODO-list, but not available yet.
213
+
214
+ ##### typein_attributes
215
+
216
+ ```javascript
217
+ // 0.0.x
218
+ _sbjs.push(['_setTypeinAttributes', '(typein)', '(typein)']);
219
+
220
+
221
+ //1.0.0
222
+ typein_attributes: {
223
+ source: '(direct)',
224
+ medium: '(none)'
225
+ }
226
+ ```
227
+
228
+ In `0.0.x` default `utm_source` & `utm_medium` values for `typein` traffic was `(typein)`. And they differ from Google Analytics values: `(direct)` & `(none)`. So I made them equal by default.
229
+
230
+ How to update.
231
+
232
+ If you haven't used `_setTypeinAttributes` and wish to keep `utm_source` & `utm_medium` values as `(typein)`, then you need to add:
233
+
234
+ ```javascript
235
+ typein_attributes: {
236
+ source: '(typein)',
237
+ medium: '(typein)'
238
+ }
239
+ ```
240
+
241
+ Otherwise just don't use this setting. Values will be `(direct)` & `(none)`.
242
+
243
+ ##### timezone_offset
244
+
245
+ ```javascript
246
+ // 0.0.x
247
+ _sbjs.push(['_setTimeZoneOffset', 3]);
248
+
249
+ //1.0.0
250
+ timezone_offset: 3
251
+ ```
252
+
253
+ Nothing changed except default behaviour. In `0.0.x`, if no custom value was set, time was normalized to UTC. `1.0.0` have no normalization by default, script uses user's system time.
254
+
255
+ Example. Your visitor is in London (`UTC +00:00`). His local time is `03:00 AM`. If no `timezone_offset` was set, the time in cookie will be `03:00 AM`. Another visitor at the same moment is from Berlin (`UTC +01:00`) and his local time is `04:00 AM`. The time in cookie will be `04:00 AM`.
256
+
257
+ If you want to normalize time of all visitors (let it be `UTC +03:00` for example), you should set it via `timezone_offset: 3`. So the time in cookies of both visitors will be `06:00 AM`.
258
+
259
+ ##### callback
260
+
261
+ ```javascript
262
+ callback: doSmth
263
+ ```
264
+
265
+ No workarounds anymore, just pass the name of the function to `callback` option, and it will be executed right after the cookies will be set. Callback will get the object with `sbjs` data as argument.
266
+
267
+ ```javascript
268
+ sbjs.init({ callback: go });
269
+
270
+ function go(sb) {
271
+ console.log('Cookies are set! Your current source is: ' + sb.current.src);
272
+ }
273
+ ```
274
+
275
+ ### Get data
276
+
277
+ `get_sbjs` is gone. Grab the data through `sbjs.get` method.
278
+
279
+ If you don't want to replace `get_sbjs` in your code, just do this:
280
+
281
+ ```javascript
282
+ var get_sbjs = sbjs.get;
283
+
284
+ // and your old code is fine
285
+ document.getElementById('user-source').innerHTML = get_sbjs.current.src;
286
+ ```
287
+
288
+ ### Cookies
289
+
290
+ Changed params delimiter in cookies: from `|` to `|||`. Cookies will be automatically upgraded by migration tool without data loss. You don't have to worry about this change unless you parse these cookies by yourself.
291
+
292
+
293
+ That's it. If you have any questions — [place an issue](https://github.com/alexfedoseev/sourcebuster-js/issues/new).
package/bower.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "sourcebuster",
3
+ "version": "1.0.5",
4
+ "description": "Get sources of your site's visitors (utm / organic / referral / typein).",
5
+ "homepage": "https://github.com/alexfedoseev/sourcebuster-js",
6
+ "authors": [
7
+ {
8
+ "name": "Alex Fedoseev",
9
+ "email": "alex.fedoseev@gmail.com",
10
+ "homepage": "http://www.alexfedoseev.com"
11
+ }
12
+ ],
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/alexfedoseev/sourcebuster-js.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/alexfedoseev/sourcebuster-js/issues"
20
+ },
21
+ "main": "./dist/sourcebuster.min.js",
22
+ "ignore": [
23
+ ".*",
24
+ "**/.*",
25
+ "package.json",
26
+ "gulpfile.js",
27
+ "node_modules",
28
+ "bower_components",
29
+ "test",
30
+ "tests",
31
+ "src",
32
+ "lib"
33
+ ],
34
+ "dependencies": {}
35
+ }