forked from chrisle/seer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleAnalytics.html
858 lines (573 loc) · 20.6 KB
/
GoogleAnalytics.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Namespace: GoogleAnalytics</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http:https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le styles -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<link href="css/seerjs.css" rel="stylesheet">
<link href="js/google-code-prettify/prettify.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="css/bootstrap-responsive.min.css" rel="stylesheet">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11852503-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http:https://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body onload="prettyPrint()">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.html">Seer SEO Toolbox</a>
<div class="nav-collapse">
<ul class="nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#apis"> APIs <b class="caret"></b> </a>
<ul class="dropdown-menu">
<!-- <li><a href="#">Google Adwords</a></li> -->
<li><a href="GoogleAnalytics.html">Google Analytics</a></li>
<li><a href="Klout.html">Klout</a></li>
<li><a href="Majestic.html">Majestic</a></li>
<li><a href="Raven.html">Raven</a></li>
<li><a href="Seomoz.html">SEOmoz</a></li>
<li><a href="Twitter.html">Twitter</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#Architecture"> Other <b class="caret"></b> </a>
<ul class="dropdown-menu">
<li><a href="GoogleScraper.html">Google Scraper</a></li>
<li><a href="OnPage.html">On-page Analysis</a></li>
<li><a href="Redirection.html">Redirection</a></li>
<li><a href="Utils.html">Utilities</a></li>
<li><a href="ArrayTransform.html">Arrays and cells</a></li>
<li><a href="Hashes.html">Hash Calculations</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container" id="seerjs-docs">
<div class="page-header">
<h1>Google Analytics API</h1>
</div>
<div class="row">
<div class="span4">
<h2>
<a href="#getGaKeywordCount">getGaKeywordCount</a>
</h2>
<p>Gets the number of keywords driving traffic to a profile between two
dates. <p class="muted"><strong>*</strong> May be inconsistant with the
website</p></p>
</div>
<div class="span4">
<h2>
<a href="#getGaMetric">getGaMetric</a>
</h2>
<p>Gets analytics data from Google Analytics to create custom
reports for multiple clients and profiles.</p>
</div>
</div>
<div class="row">
<div class="span12 columns">
<section id="getGaKeywordCount">
<div class="page-header">
<h1 id="getGaKeywordCount">
getGaKeywordCount
</h1>
</div>
<div class="row">
<div class="span12 columns">
<h3>Function</h3>
<pre class="prettyprint">=getGaKeywordCount(profileId, startDate, endDate)</pre>
</div>
</div>
<div class="row">
<div class="span3 columns">
<h3>Details</h3>
<p> This function gets the number of keywords that are driving traffic to a
specific profile between two dates.
It works by collecting all the keywords that drove traffic between the
start date and end date and returning the total number of keywords.
<div class="alert">
<b>Inconsistancy:</b> Google doesn't provide a keyword count in the API so
this count may not match up to the website.</b>
</div>
<div class="alert alert-error">
<b>Limitation:</b> Does not work on high traffic accounts.
</div> </p>
</div>
<div class="span9 columns">
<h3>Parameters</h3>
<p>
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>profileId</code></td>
<td class="type">
Number
</td>
<td class="description last">Profile ID from the Profile ID sheet</td>
</tr>
<tr>
<td class="name"><code>startDate</code></td>
<td class="type">
Date
</td>
<td class="description last">Starting date</td>
</tr>
<tr>
<td class="name"><code>endDate</code></td>
<td class="type">
Date
</td>
<td class="description last">Ending date</td>
</tr>
</tbody>
</table>
</p>
</div>
</div>
<div class="page-header">
<h3>Examples</h3>
</div>
<div class="row">
<div class="span3">
<p>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: 11/01/2011
A3: 11/02/2011
=getGaKeywordCount(A1, A2, A3)</pre> </p>
</div>
</div>
</section>
</div>
</div>
<div class="row">
<div class="span12 columns">
<section id="getGaMetric">
<div class="page-header">
<h1 id="getGaMetric">
getGaMetric
</h1>
</div>
<div class="row">
<div class="span12 columns">
<h3>Function</h3>
<pre class="prettyprint">=getGaMetric(profileId, metric, startDate, endDate, optFilter, optDimensions, optSegment, optSort, optIncludeHeaders, optMax, optEnableSleep)</pre>
</div>
</div>
<div class="row">
<div class="span3 columns">
<h3>Details</h3>
<p> <p>Gets analytics data by metrics and dimensions within a date range.</p>
<p>It will return an error if the date is in the future or if the start
date is after the begining date.</p>
<hr/>
<div class="alert alert-success">
<strong>Tip:</strong> A complete list of metrics and dimensions is available on
the <a href="http:https://code.google.com/apis/analytics/docs/gdata/dimsmets/dimsmets.html" target="_blank">Google Analytics API</a> website.
</div> </p>
</div>
<div class="span9 columns">
<h3>Parameters</h3>
<p>
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>profileId</code></td>
<td class="type">
Number
</td>
<td class="description last">The ID number for the profile</td>
</tr>
<tr>
<td class="name"><code>metric</code></td>
<td class="type">
String
</td>
<td class="description last">Google Analytics metric you want to get data for. <br/>
<span class="label label-info">Note</span>
You must add <code>ga:</code> if you're using multiple metrics in
on the same function. It's not required if you only use one metric.
<div class="well">
<h6>Common metrics</h6>
<dl>
<dt>ga:visits </dt><dd>Total number of visitors to your website for the requested time period.</dd>
<dt>ga:bounces </dt><dd>The total number of single-page (or event) sessions to your website.</dd>
<dt>ga:goal(n)completions </dt><dd>The total number of completions for the requested goal number.</dd>
<dt>ga:totalEvents </dt><dd>The total number of events for the profile, across all categories</dd>
<dt>ga:pageLoadTime </dt><dd>Total Page Load Time is the amount of time (in milliseconds).</dd>
<dt>ga:transactions </dt><dd>The total number of transactions.</dd>
</dl>
</div></td>
</tr>
<tr>
<td class="name"><code>startDate</code></td>
<td class="type">
Date
</td>
<td class="description last">Starting date</td>
</tr>
<tr>
<td class="name"><code>endDate</code></td>
<td class="type">
Date
</td>
<td class="description last">Ending date<br/>
<span class="label label-important">Limitation</span>
Long date ranges may timeout with high traffic profiles. Try a
shorter date range.<br/>
<span class="label label-warning">Warning</span>
Long date ranges may result in sampled numbers.</td>
</tr>
<tr>
<td class="name"><code>optFilter</code></td>
<td class="type">
Filter
</td>
<td class="description last"><em class="muted">(Optional)</em> Filter data from your results.
<h6>Available operators</h6>
<ul class="unstyled">
<li><code>==</code> Equals</li>
<li><code>!=</code> Does not equal</li>
<li><code>> </code> Greater than</li>
<li><code>< </code> Less than</li>
<li><code>>=</code> Greater than or equal to</li>
<li><code><=</code> Less than or equal to</li>
</ul>
<h6></h6>
<ul class="unstyled">
<li><code>;</code> And </li>
<li><code>,</code> Or</li>
</ul>
See at the <a href="#multiple_filters">examples below</a> or go to the
<a href="http:https://code.google.com/apis/analytics/docs/gdata/v2/gdataReferenceDataFeed.html#filters">
filters section</a> on the Google Analytics' API website for more
details.</td>
</tr>
<tr>
<td class="name"><code>optDimensions</code></td>
<td class="type">
String
</td>
<td class="description last"><em class="muted">(Optional)</em> Dimentions.
<h6>Available operators</h6>
<ul class="unstyled">
<li><code>==</code> Exact match</li>
<li><code>!=</code> Does not match</li>
<li><code>=@</code> Contains substring</li>
<li><code>!@</code> Does not contain substring</li>
<li><code>=~</code> Matches regular expression</li>
<li><code>!~</code> Does not match regular expression</li>
</ul>
<div class="well">
<h6>Common dimensions</h6>
<dl>
<dt>ga:visitorType </dt> <dd>A boolean indicating if a visitor is new or returning. Possible values: New Visitor, Returning Visitor..</dd>
<dt>ga:referralPath </dt> <dd>The path of the referring URL.</dd>
<dt>ga:source </dt> <dd>The domain of the referring URL, or "google" with AdWords autotagging.</dd>
<dt>ga:medium </dt> <dd>May be "organic", "referral" or "ppc" if used with AdWords autotagging.</dd>
<dt>ga:keyword </dt> <dd>The keyword used to reach the website.</dd>
<dt>ga:city </dt> <dd>The cities of website visitors.</dd>
<dt>ga:region </dt> <dd>The state of website visitors.</dd>
</dl>
</div>
See <a href="http:https://code.google.com/apis/analytics/docs/gdata/v2/gdataReferenceDataFeed.html#dimensions">
dimensions</a> on the Google Analytics' API website for more details.</td>
</tr>
<tr>
<td class="name"><code>optSegment</code></td>
<td class="type">
Number
</td>
<td class="description last"><em class="muted">(Optional)</em> Segment ID</td>
</tr>
<tr>
<td class="name"><code>optSort</code></td>
<td class="type">
String
</td>
<td class="description last"><em class="muted">(Optional)</em> Sort</td>
</tr>
<tr>
<td class="name"><code>optIncludeHeaders</code></td>
<td class="type">
Boolean
</td>
<td class="description last"><em class="muted">(Optional)</em> Include headers (true or false)</td>
</tr>
<tr>
<td class="name"><code>optMax</code></td>
<td class="type">
Number
</td>
<td class="description last"><em class="muted">(Optional)</em> Maximum rows</td>
</tr>
<tr>
<td class="name"><code>optEnableSleep</code></td>
<td class="type">
Number
</td>
<td class="description last"><em class="muted">(Optional)</em> Slow down API calls (default is true)</td>
</tr>
</tbody>
</table>
</p>
</div>
</div>
<div class="page-header">
<h3>Examples</h3>
</div>
<div class="row">
<div class="span3">
<p>
<h4>The basics:<br/>
<small>Number of visitors between Nov 11, 2011 and Nov 20, 2011</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 11/01/2011
A4: 11/20/2011
=getGaMetric(A1, A2, A3, A4)</pre> </p>
</div>
<div class="span3">
<p>
<h4>One filter:<br/>
<small>Number of organic visitors between Nov 11, 2011 and Nov 20, 2011.</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 11/01/2011
A4: 11/02/2011
A5: ga:medium==organic
=getGaMetric(A1, A2, A3, A4, A5)</pre> </p>
</div>
<div class="span3">
<p>
<a name="multiple_filters"></a>
<h4>Filter A (and) Filter B:<br/>
<small>
Get the number of visitors between Nov 11, 2011 and Nov 20, 2011
that is both organic traffic and came in using the keyword
"seo company"
</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 11/01/2011
A4: 11/02/2011
A5: ga:medium==organic;ga:keyword==seo company
=getGaMetric(A1, A2, A3, A4, A5)</pre> </p>
</div>
<div class="span3">
<p>
<h4>Filter A (or) Filter B:<br/>
<small>
Get the number of visitors between Nov 11, 2011 and Nov 20, 2011
that came in using the keyword "seo company" or "philadelphia seo"
</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 11/01/2011
A4: 11/02/2011
A5: ga:keyword==seo company,ga:keyword==philadelphia seo
=getGaMetric(A1, A2, A3, A4, A5)</pre> </p>
</div>
<div class="span3">
<p>
<h4>Visits by month (dimensions)<br/>
<small> Get visits in the date range broken down by month. </small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 01/01/2011
A4: 06/30/2011
A5: ga:month
=getGaMetric(A1, A2, A3, A4, , A5, , , true)
// Will return 6 rows, one per month, January to June.</pre> </p>
</div>
<div class="span3">
<p>
<h4>Visits by week (dimensions)<br/>
<small> Get visits in the date range broken down by week. </small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 01/01/2011
A4: 12/31/2011
A5: ga:week
=getGaMetric(A1, A2, A3, A4, , A5, , , true)
// Will return 52 rows numbered 1 to 52 for each week in 2011
// Tip: If you want to convert the week number to a date, add this:
D1: =getMonday(A3)
D2: =D1+7
D3: =D2+7
D4: =D3+7
D5: .... and so on.</pre> </p>
</div>
<div class="span3">
<p>
<h4>Visits by city (dimensions)<br/>
<small> Get visits in the date range broken down by city. </small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 01/01/2011
A4: 06/30/2011
A5: ga:city
=getGaMetric(A1, A2, A3, A4, , A5, , , true)</pre> </p>
</div>
<div class="span3">
<p>
<h4>Many metrics & many dimensions combo: <br/>
<small>
Creates two columns visits and transactions, broken down into rows
by month and year
</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: ga:visits,ga:transactions
A3: 01/01/2011
A4: 12/30/2012
A5: ga:month,ga:year
=getGaMetric(A1, A2, A3, A4, , A5, , , true)</pre> </p>
</div>
<div class="span3">
<p>
<h4>Referring links: <br/>
<small>
Get referral URLs that came to the site between two dates. <br/><br/>
Note: Visits is added because a metric is required. Google Docs will
create three columns: the domain, the path, and the number of visits.
</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: visits
A3: 01/01/2011
A4: 03/30/2011
A5: ga:source,ga:referralPath
=getGaMetric(A1, A2, A3, A4, , A5, , , true)</pre> </p>
</div>
<div class="span3">
<p>
<h4>Crazy town: <br/>
<small>
Get columns for visits and bounces that came from organic traffic,
using the keyword "seo company". Break it out by month, and the
visitor's city, for the first quarter of 2011. Oh, and also include
column headers. Zing!
</small>
</h4>
</p>
</div>
<div class="span9">
<p> <pre class="prettyprint">Cells:
A1: 12345678
A2: ga:visits,ga:bounces
A3: 01/01/2011
A4: 03/30/2011
A5: ga:medium==organic;ga:keyword=seo company
A6: ga:month,ga:city
=getGaMetric(A1, A2, A3, A4, A5, A6, , , true)</pre> </p>
</div>
</div>
</section>
</div>
</div>
<footer class="footer">
<div class="row">
<div class="span12 columns">
<hr />
<p>
By <a href="http:https://www.chrisle.me">Chris Le</a> (<a href="https://twitter.com/iamchrisle">@iamchrisle</a>) &
<a href="http:https://www.seerinteractive.com">Seer Interactive (<a href="https://twitter.com/seerinteractive">@SEERinteractive</a>)
</p>
</div>
</div>
</footer>
</div>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/google-code-prettify/prettify.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>