Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
insert_ga_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
21 
22 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_
23 #define NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_
24 
26 #include "pagespeed/kernel/base/basictypes.h"
27 #include "pagespeed/kernel/base/string.h"
28 
29 namespace net_instaweb {
30 
31 class HtmlCharactersNode;
32 class HtmlElement;
33 class RewriteDriver;
34 class Statistics;
35 class Variable;
36 
37 extern const char kGAExperimentSnippet[];
38 extern const char kGAJsSnippet[];
39 extern const char kGASpeedTracking[];
40 
43 class InsertGAFilter : public CommonFilter {
44  public:
45  explicit InsertGAFilter(RewriteDriver* rewrite_driver);
46  virtual ~InsertGAFilter();
47 
49  static void InitStats(Statistics* stats);
50 
51  virtual void StartDocumentImpl();
52  virtual void StartElementImpl(HtmlElement* element);
53  virtual void EndElementImpl(HtmlElement* element);
55  virtual void Characters(HtmlCharactersNode* characters);
56 
57  virtual const char* Name() const { return "InsertGASnippet"; }
58 
59  private:
61  GoogleString ConstructExperimentSnippet() const;
62 
64  GoogleString MakeFullExperimentSnippet() const;
65 
67  void HandleEndBody(HtmlElement* body);
68 
71  void AddScriptNode(HtmlElement* current_element, GoogleString text,
72  bool insert_immediately_after_current);
73 
76  void HandleEndScript(HtmlElement* script);
77 
80  bool FoundSnippetInBuffer() const;
81 
83  Variable* inserted_ga_snippets_count_;
84 
87  HtmlElement* script_element_;
89  bool added_analytics_js_;
91  bool added_experiment_snippet_;
92 
94  GoogleString ga_id_;
95 
98  GoogleString buffer_;
99 
101  bool found_snippet_;
102 
104  bool increase_speed_tracking_;
105 
106  DISALLOW_COPY_AND_ASSIGN(InsertGAFilter);
107 };
108 
109 }
110 
111 #endif
Definition: common_filter.h:48
static void InitStats(Statistics *stats)
Set up statistics for this filter.
virtual void StartDocumentImpl()
Definition: insert_ga_filter.h:43
Definition: rewrite_driver.h:98
virtual void Characters(HtmlCharactersNode *characters)
HTML Events we expect to be in <script> elements.