1 | <?php |
||
7 | class GoogleTagManager |
||
8 | { |
||
9 | use Macroable; |
||
10 | |||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $id; |
||
15 | |||
16 | /** |
||
17 | * @var bool |
||
18 | */ |
||
19 | protected $enabled; |
||
20 | |||
21 | /** |
||
22 | * @var \Spatie\GoogleTagManager\DataLayer |
||
23 | */ |
||
24 | protected $dataLayer; |
||
25 | |||
26 | /** |
||
27 | * @var \Spatie\GoogleTagManager\DataLayer |
||
28 | */ |
||
29 | protected $flashDataLayer; |
||
30 | |||
31 | /** |
||
32 | * @var \Illuminate\Support\Collection |
||
33 | */ |
||
34 | protected $pushDataLayer; |
||
35 | |||
36 | /** |
||
37 | * @param string $id |
||
38 | */ |
||
39 | public function __construct($id) |
||
48 | |||
49 | /** |
||
50 | * Return the Google Tag Manager id. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function id() |
||
58 | |||
59 | /** |
||
60 | * Check whether script rendering is enabled. |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | public function isEnabled() |
||
68 | |||
69 | /** |
||
70 | * Enable Google Tag Manager scripts rendering. |
||
71 | */ |
||
72 | public function enable() |
||
76 | |||
77 | /** |
||
78 | * Disable Google Tag Manager scripts rendering. |
||
79 | */ |
||
80 | public function disable() |
||
84 | |||
85 | /** |
||
86 | * Add data to the data layer. |
||
87 | * |
||
88 | * @param array|string $key |
||
89 | * @param mixed $value |
||
90 | */ |
||
91 | public function set($key, $value = null) |
||
95 | |||
96 | /** |
||
97 | * Retrieve the data layer. |
||
98 | * |
||
99 | * @return \Spatie\GoogleTagManager\DataLayer |
||
100 | */ |
||
101 | public function getDataLayer() |
||
105 | |||
106 | /** |
||
107 | * Add data to the data layer for the next request. |
||
108 | * |
||
109 | * @param array|string $key |
||
110 | * @param mixed $value |
||
111 | */ |
||
112 | public function flash($key, $value = null) |
||
116 | |||
117 | /** |
||
118 | * Retrieve the data layer's data for the next request. |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public function getFlashData() |
||
126 | |||
127 | /** |
||
128 | * Add data to be pushed to the data layer. |
||
129 | * |
||
130 | * @param array|string $key |
||
131 | * @param mixed $value |
||
132 | */ |
||
133 | public function push($key, $value = null) |
||
139 | |||
140 | /** |
||
141 | * Retrieve the data layer's data for the next request. |
||
142 | * |
||
143 | * @return \Illuminate\Support\Collection |
||
144 | */ |
||
145 | public function getPushData() |
||
149 | |||
150 | /** |
||
151 | * Clear the data layer. |
||
152 | */ |
||
153 | public function clear() |
||
158 | |||
159 | /** |
||
160 | * Utility function to dump an array as json. |
||
161 | * |
||
162 | * @param array $data |
||
163 | * @return string |
||
164 | */ |
||
165 | public function dump($data) |
||
169 | } |
||
170 |