1 | <?php |
||
7 | class GoogleTagManager |
||
8 | { |
||
9 | use Macroable; |
||
10 | |||
11 | /** |
||
12 | * @var string[] |
||
13 | */ |
||
14 | protected $id; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $layer; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | protected $enabled; |
||
25 | |||
26 | /** |
||
27 | * @var \Spatie\GoogleTagManager\DataLayer |
||
28 | */ |
||
29 | protected $dataLayer; |
||
30 | |||
31 | /** |
||
32 | * @var \Spatie\GoogleTagManager\DataLayer |
||
33 | */ |
||
34 | protected $flashDataLayer; |
||
35 | |||
36 | /** |
||
37 | * @var \Spatie\GoogleTagManager\DataLayer |
||
38 | */ |
||
39 | protected $noJSDataLayer; |
||
40 | |||
41 | /** |
||
42 | * @var \Illuminate\Support\Collection |
||
43 | */ |
||
44 | protected $pushDataLayer; |
||
45 | |||
46 | /** |
||
47 | * @param string[] $id |
||
48 | * @param string $layer |
||
49 | */ |
||
50 | public function __construct($id, $layer) |
||
61 | |||
62 | /** |
||
63 | * Return the Google Tag Manager id. |
||
64 | * |
||
65 | * @return string[] |
||
66 | */ |
||
67 | public function id() |
||
71 | |||
72 | /** |
||
73 | * Return the Google Tag Manager id. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getLayer() |
||
81 | |||
82 | /** |
||
83 | * Check whether script rendering is enabled. |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | public function isEnabled() |
||
91 | |||
92 | /** |
||
93 | * Enable Google Tag Manager scripts rendering. |
||
94 | */ |
||
95 | public function enable() |
||
99 | |||
100 | /** |
||
101 | * Disable Google Tag Manager scripts rendering. |
||
102 | */ |
||
103 | public function disable() |
||
107 | |||
108 | /** |
||
109 | * Add data to the data layer. |
||
110 | * |
||
111 | * @param array|string $key |
||
112 | * @param mixed $value |
||
113 | */ |
||
114 | public function set($key, $value = null) |
||
118 | |||
119 | /** |
||
120 | * Retrieve the data layer. |
||
121 | * |
||
122 | * @return \Spatie\GoogleTagManager\DataLayer |
||
123 | */ |
||
124 | public function getDataLayer() |
||
128 | |||
129 | /** |
||
130 | * Add data to the data layer for the next request. |
||
131 | * |
||
132 | * @param array|string $key |
||
133 | * @param mixed $value |
||
134 | */ |
||
135 | public function flash($key, $value = null) |
||
139 | |||
140 | /** |
||
141 | * Retrieve the data layer's data for the next request. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | public function getFlashData() |
||
149 | |||
150 | /** |
||
151 | * Add data to the data layer for the next request. |
||
152 | * |
||
153 | * @param array|string $key |
||
154 | * @param mixed $value |
||
155 | */ |
||
156 | public function noScript($key, $value = null) |
||
160 | |||
161 | /** |
||
162 | * Retrieve the data layer's data for the next request. |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getNoScriptData() |
||
170 | |||
171 | /** |
||
172 | * Add data to be pushed to the data layer. |
||
173 | * |
||
174 | * @param array|string $key |
||
175 | * @param mixed $value |
||
176 | */ |
||
177 | public function push($key, $value = null) |
||
183 | |||
184 | /** |
||
185 | * Retrieve the data layer's data for the next request. |
||
186 | * |
||
187 | * @return \Illuminate\Support\Collection |
||
188 | */ |
||
189 | public function getPushData() |
||
193 | |||
194 | /** |
||
195 | * Clear the data layer. |
||
196 | */ |
||
197 | public function clear() |
||
202 | |||
203 | /** |
||
204 | * Utility function to dump an array as json. |
||
205 | * |
||
206 | * @param array $data |
||
207 | * @return string |
||
208 | */ |
||
209 | public function dump($data) |
||
213 | } |
||
214 |