OpenSencillo  2016.106
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
google.analytics.goas.php
1 <?php
11 class analytics
12 {
13  protected $arr;
14 
15  public function __construct()
16  {
17  $this->arr[] = "<script>";
18  $this->arr[] = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){";
19  $this->arr[] = "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),";
20  $this->arr[] = "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)";
21  $this->arr[] = "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');";
22  }
23 
30  public function set($pref,$value,$param)
31  {
32  if(!empty($param))
33  {
34  $this->arr[] = "ga('$pref', '$value', '$param');";
35  }
36  else
37  {
38  $this->arr[] = "ga('$pref', '$value');";
39  }
40  }
41 
46  public function gadefault($id)
47  {
48  $this->arr[] = "ga('create', '$id', 'auto');";
49  $this->arr[] = "ga('send', 'pageview');";
50  }
51 
55  public function create()
56  {
57  $this->arr[] = "</script>";
58  $this->arr = implode(PHP_EOL,$this->arr);
59  return $this->arr;
60  }
61 }
62 ?>