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 | public function setId($id) |
||
65 | |||
66 | /** |
||
67 | * Check whether script rendering is enabled. |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function isEnabled() |
||
75 | |||
76 | /** |
||
77 | * Enable Google Tag Manager scripts rendering. |
||
78 | */ |
||
79 | public function enable() |
||
83 | |||
84 | /** |
||
85 | * Disable Google Tag Manager scripts rendering. |
||
86 | */ |
||
87 | public function disable() |
||
91 | |||
92 | /** |
||
93 | * Add data to the data layer. |
||
94 | * |
||
95 | * @param array|string $key |
||
96 | * @param mixed $value |
||
97 | */ |
||
98 | public function set($key, $value = null) |
||
102 | |||
103 | /** |
||
104 | * Retrieve the data layer. |
||
105 | * |
||
106 | * @return \Spatie\GoogleTagManager\DataLayer |
||
107 | */ |
||
108 | public function getDataLayer() |
||
112 | |||
113 | /** |
||
114 | * Add data to the data layer for the next request. |
||
115 | * |
||
116 | * @param array|string $key |
||
117 | * @param mixed $value |
||
118 | */ |
||
119 | public function flash($key, $value = null) |
||
123 | |||
124 | /** |
||
125 | * Retrieve the data layer's data for the next request. |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function getFlashData() |
||
133 | |||
134 | /** |
||
135 | * Add data to be pushed to the data layer. |
||
136 | * |
||
137 | * @param array|string $key |
||
138 | * @param mixed $value |
||
139 | */ |
||
140 | public function push($key, $value = null) |
||
146 | |||
147 | /** |
||
148 | * Retrieve the data layer's data for the next request. |
||
149 | * |
||
150 | * @return \Illuminate\Support\Collection |
||
151 | */ |
||
152 | public function getPushData() |
||
156 | |||
157 | /** |
||
158 | * Clear the data layer. |
||
159 | */ |
||
160 | public function clear() |
||
165 | |||
166 | /** |
||
167 | * Utility function to dump an array as json. |
||
168 | * |
||
169 | * @param array $data |
||
170 | * @return string |
||
171 | */ |
||
172 | public function dump($data) |
||
176 | } |
||
177 |