Page Speed Optimization Libraries  1.3.25.1
net/instaweb/rewriter/public/insert_ga_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00021 
00022 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_
00023 #define NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_
00024 
00025 #include "net/instaweb/rewriter/public/common_filter.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/string.h"
00028 
00029 namespace net_instaweb {
00030 
00031 class HtmlCharactersNode;
00032 class HtmlElement;
00033 class RewriteDriver;
00034 class Statistics;
00035 class Variable;
00036 
00037 extern const char kGAFuriousSnippet[];
00038 extern const char kGAJsSnippet[];
00039 extern const char kGASpeedTracking[];
00040 
00043 class InsertGAFilter : public CommonFilter {
00044  public:
00045   explicit InsertGAFilter(RewriteDriver* rewrite_driver);
00046   virtual ~InsertGAFilter();
00047 
00049   static void InitStats(Statistics* stats);
00050 
00051   virtual void StartDocumentImpl();
00052   virtual void StartElementImpl(HtmlElement* element);
00053   virtual void EndElementImpl(HtmlElement* element);
00055   virtual void Characters(HtmlCharactersNode* characters);
00056 
00057   virtual const char* Name() const { return "InsertGASnippet"; }
00058 
00059  private:
00061   GoogleString ConstructFuriousSnippet() const;
00062 
00064   GoogleString MakeFullFuriousSnippet() const;
00065 
00067   void HandleEndBody(HtmlElement* body);
00068 
00071   void AddScriptNode(HtmlElement* current_element, GoogleString text,
00072                      bool insert_immediately_after_current);
00073 
00076   void HandleEndScript(HtmlElement* script);
00077 
00080   bool FoundSnippetInBuffer() const;
00081 
00083   Variable* inserted_ga_snippets_count_;
00084 
00087   HtmlElement* script_element_;
00089   bool added_analytics_js_;
00091   bool added_furious_snippet_;
00092 
00094   GoogleString ga_id_;
00095 
00098   GoogleString buffer_;
00099 
00101   bool found_snippet_;
00102 
00104   bool increase_speed_tracking_;
00105 
00106   DISALLOW_COPY_AND_ASSIGN(InsertGAFilter);
00107 };
00108 
00109 }  
00110 
00111 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_INSERT_GA_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines