1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
12 | abstract class Kohana_Service_GoogleAnalytics extends Service implements Service_Type_Javascript { |
||
13 | |||
14 | const SCOPE_VISITOR = 1; |
||
15 | |||
16 | const SCOPE_SESSION = 2; |
||
17 | |||
18 | const SCOPE_PAGE = 3; |
||
19 | |||
20 | protected $_access_token; |
||
21 | |||
22 | protected $_events_queue = array(); |
||
23 | |||
24 | protected $_custom_vars = array(); |
||
25 | |||
26 | protected $_transaction = array(); |
||
27 | |||
28 | protected $_items = array(); |
||
29 | |||
30 | protected $_currency; |
||
31 | |||
32 | public function init() |
||
36 | |||
37 | public function queue() |
||
41 | |||
42 | public function custom_vars() |
||
46 | |||
47 | /** |
||
48 | * This method accepts four parameters: |
||
49 | * |
||
50 | * @param integer index — The slot for the custom variable. Required. |
||
51 | * This is a number whose value can range from 1 - 5, inclusive. |
||
52 | * A custom variable should be placed in one slot only and not be re-used across different slots. |
||
53 | * |
||
54 | * @param string $name — The name for the custom variable. Required. |
||
55 | * This is a string that identifies the custom variable and appears in the top-level |
||
56 | * Custom Variables report of the Analytics reports. |
||
57 | * |
||
58 | * @param string $value — The value for the custom variable. Required. |
||
59 | * This is a string that is paired with a name. |
||
60 | * You can pair a number of values with a custom variable name. |
||
61 | * The value appears in the table list of the UI for a selected variable name. |
||
62 | * Typically, you will have two or more values for a given name. |
||
63 | * For example, you might define a custom variable name gender and supply male and female as two possible values. |
||
64 | * |
||
65 | * @param integer $opt_scope — The scope for the custom variable. Optional. |
||
66 | * As described above, the scope defines the level of user engagement with your site. |
||
67 | * It is a number whose possible values are 1 (visitor-level), 2 (session-level), |
||
68 | * or 3 (page-level). When left undefined, the custom variable scope defaults to page-level interaction. |
||
69 | */ |
||
70 | public function set_custom_var($index, $name, $value, $opt_scope = self::SCOPE_PAGE) |
||
82 | |||
83 | public function set_currency($currency) |
||
90 | |||
91 | public function set_transaciton(array $transaction) |
||
98 | |||
99 | public function set_items(array $items) |
||
106 | |||
107 | public function track_event($category, $action, $label = NULL, $value = NULL, $opt_noninteraction = NULL) |
||
134 | |||
135 | /** |
||
136 | * Render the required code |
||
137 | * @return string |
||
138 | */ |
||
139 | public function code() |
||
166 | |||
167 | protected function events_code() |
||
181 | |||
182 | protected function currency_code() |
||
193 | |||
194 | protected function ecommerce_code() |
||
215 | |||
216 | protected function custom_vars_code() |
||
227 | |||
228 | public function head() |
||
232 | |||
233 | public function body() |
||
237 | } |
||
238 |