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 | * @param string $id |
||
28 | */ |
||
29 | public function __construct($id) |
||
36 | |||
37 | /** |
||
38 | * Return the Google Tag Manager id. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function id() |
||
46 | |||
47 | /** |
||
48 | * Check whether script rendering is enabled. |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | public function isEnabled() |
||
56 | |||
57 | /** |
||
58 | * Enable Google Tag Manager scripts rendering. |
||
59 | */ |
||
60 | public function enable() |
||
64 | |||
65 | /** |
||
66 | * Disable Google Tag Manager scripts rendering. |
||
67 | */ |
||
68 | public function disable() |
||
72 | |||
73 | /** |
||
74 | * Add data to the data layer. |
||
75 | * |
||
76 | * @param array|string $key |
||
77 | * @param mixed $value |
||
78 | */ |
||
79 | public function set($key, $value = null) |
||
83 | |||
84 | /** |
||
85 | * Retrieve the data layer |
||
86 | * |
||
87 | * @return \Spatie\GoogleTagManager\DataLayer |
||
88 | */ |
||
89 | public function getDataLayer() |
||
93 | |||
94 | /** |
||
95 | * Clear the data layer |
||
96 | */ |
||
97 | public function clear() |
||
101 | |||
102 | /** |
||
103 | * Utility function to dump an array as json |
||
104 | * |
||
105 | * @param array $data |
||
106 | * @return string |
||
107 | */ |
||
108 | public function dump($data) |
||
112 | } |
||
113 |