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 | * Set the Google Tag Manager id. |
||
61 | * |
||
62 | * @param string $id |
||
63 | */ |
||
64 | public function setId($id) |
||
68 | |||
69 | /** |
||
70 | * Check whether script rendering is enabled. |
||
71 | * |
||
72 | * @return bool |
||
73 | */ |
||
74 | public function isEnabled() |
||
78 | |||
79 | /** |
||
80 | * Enable Google Tag Manager scripts rendering. |
||
81 | */ |
||
82 | public function enable() |
||
86 | |||
87 | /** |
||
88 | * Disable Google Tag Manager scripts rendering. |
||
89 | */ |
||
90 | public function disable() |
||
94 | |||
95 | /** |
||
96 | * Add data to the data layer. |
||
97 | * |
||
98 | * @param array|string $key |
||
99 | * @param mixed $value |
||
100 | */ |
||
101 | public function set($key, $value = null) |
||
105 | |||
106 | /** |
||
107 | * Retrieve the data layer. |
||
108 | * |
||
109 | * @return \Spatie\GoogleTagManager\DataLayer |
||
110 | */ |
||
111 | public function getDataLayer() |
||
115 | |||
116 | /** |
||
117 | * Add data to the data layer for the next request. |
||
118 | * |
||
119 | * @param array|string $key |
||
120 | * @param mixed $value |
||
121 | */ |
||
122 | public function flash($key, $value = null) |
||
126 | |||
127 | /** |
||
128 | * Retrieve the data layer's data for the next request. |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getFlashData() |
||
136 | |||
137 | /** |
||
138 | * Add data to be pushed to the data layer. |
||
139 | * |
||
140 | * @param array|string $key |
||
141 | * @param mixed $value |
||
142 | */ |
||
143 | public function push($key, $value = null) |
||
149 | |||
150 | /** |
||
151 | * Retrieve the data layer's data for the next request. |
||
152 | * |
||
153 | * @return \Illuminate\Support\Collection |
||
154 | */ |
||
155 | public function getPushData() |
||
159 | |||
160 | /** |
||
161 | * Clear the data layer. |
||
162 | */ |
||
163 | public function clear() |
||
168 | |||
169 | /** |
||
170 | * Utility function to dump an array as json. |
||
171 | * |
||
172 | * @param array $data |
||
173 | * @return string |
||
174 | */ |
||
175 | public function dump($data) |
||
179 | } |
||
180 |