Conditions | 27 |
Paths | 6146 |
Total Lines | 119 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | public function frontend_tracking_options( ) { |
||
61 | global $wp_query; |
||
62 | $options = array(); |
||
63 | |||
64 | $ua_code = monsterinsights_get_ua_to_output(); |
||
65 | if ( empty( $ua_code ) ) { |
||
66 | return $options; |
||
67 | } |
||
68 | |||
69 | $track_user = monsterinsights_track_user(); |
||
70 | |||
71 | if ( ! $track_user ) { |
||
72 | $options['create'] = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( 'auto' ) . "'"; |
||
73 | $options['forceSSL'] = "'set', 'forceSSL', true"; |
||
74 | $options['send'] = "'send','pageview'"; |
||
75 | return $options; |
||
76 | } |
||
77 | |||
78 | $domain = esc_attr( monsterinsights_get_option( 'subdomain_tracking', 'auto' ) ); |
||
79 | |||
80 | $cross_domains = monsterinsights_get_option( 'cross_domains', array() ); |
||
81 | $allow_anchor = monsterinsights_get_option( 'allow_anchor', false ); |
||
82 | |||
83 | |||
84 | $create = array(); |
||
85 | if ( $allow_anchor ) { |
||
86 | $create['allowAnchor'] = true; |
||
87 | } |
||
88 | |||
89 | if ( is_array( $cross_domains ) && ! empty( $cross_domains ) ) { |
||
|
|||
90 | $create['allowLinker'] = true; |
||
91 | } |
||
92 | |||
93 | if ( class_exists( 'MonsterInsights_AMP' ) ) { |
||
94 | $create['useAmpClientId'] = true; |
||
95 | } |
||
96 | |||
97 | $create = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_create', $create ); |
||
98 | |||
99 | if ( $create && ! empty( $create ) && is_array( $create ) ) { |
||
100 | $create = json_encode( $create ); |
||
101 | $create = str_replace( '"', "'", $create ); |
||
102 | $options['create'] = "'create', '" . esc_js( $ua_code ). "', '" . esc_js( $domain ) . "', " . $create; |
||
103 | } else { |
||
104 | $options['create'] = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( $domain ) . "'"; |
||
105 | } |
||
106 | |||
107 | $options['forceSSL'] = "'set', 'forceSSL', true"; |
||
108 | |||
109 | $code = monsterinsights_get_option( 'custom_code', false ); |
||
110 | if ( ! empty( $code ) ) { |
||
111 | // Add custom code to the view |
||
112 | $options['custom_code'] = array( |
||
113 | 'type' => 'custom_code', |
||
114 | 'value' => stripslashes( $code ), |
||
115 | ); |
||
116 | } |
||
117 | |||
118 | // Anonymous data |
||
119 | if ( monsterinsights_get_option( 'anonymize_ips', false ) ) { |
||
120 | $options['anonymize_ips'] = "'set', 'anonymizeIp', true"; |
||
121 | } |
||
122 | |||
123 | $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_scripts', $options ); |
||
124 | |||
125 | // add demographics |
||
126 | if ( monsterinsights_get_option( 'demographics', false ) ) { |
||
127 | $options['demographics'] = "'require', 'displayfeatures'"; |
||
128 | } |
||
129 | |||
130 | // Add Enhanced link attribution. |
||
131 | if ( monsterinsights_get_option( 'link_attribution', false ) ) { |
||
132 | $options['enhanced_link_attribution'] = "'require', 'linkid', 'linkid.js'"; |
||
133 | } |
||
134 | |||
135 | // Add cross-domain tracking. |
||
136 | if ( is_array( $cross_domains ) && ! empty( $cross_domains ) ) { |
||
137 | $options['cross_domain_tracking'] = "'require', 'linker'"; |
||
138 | $cross_domains_strings = array(); |
||
139 | foreach ( $cross_domains as $cross_domain ) { |
||
140 | if ( ! isset( $cross_domain['domain'] ) ) { |
||
141 | continue; |
||
142 | } |
||
143 | $cross_domains_strings[] = '\'' . $cross_domain['domain'] . '\''; |
||
144 | } |
||
145 | if ( ! empty( $cross_domains_strings ) ) { |
||
146 | $cross_domains_strings = implode( ',', $cross_domains_strings ); |
||
147 | $options['cross_domains'] = "'linker:autoLink', [$cross_domains_strings]"; |
||
148 | } |
||
149 | } |
||
150 | |||
151 | $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_pageview', $options ); |
||
152 | $options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version ); |
||
153 | |||
154 | if ( is_404() ) { |
||
155 | if ( monsterinsights_get_option( 'hash_tracking', false ) ) { |
||
156 | $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer"; |
||
157 | } else { |
||
158 | $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer"; |
||
159 | } |
||
160 | } else if ( $wp_query->is_search ) { |
||
161 | $pushstr = "'send','pageview','/?s="; |
||
162 | if ( (int) $wp_query->found_posts === 0 ) { |
||
163 | $options['send'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'"; |
||
164 | } else if ( (int) $wp_query->found_posts === 1 ) { |
||
165 | $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'"; |
||
166 | } else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) { |
||
167 | $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'"; |
||
168 | } else { |
||
169 | $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'"; |
||
170 | } |
||
171 | } else if ( monsterinsights_get_option( 'hash_tracking', false ) ) { |
||
172 | $options['send'] = "'send','pageview', location.pathname + location.search + location.hash"; |
||
173 | } else { |
||
174 | $options['send'] = "'send','pageview'"; |
||
175 | } |
||
176 | |||
177 | $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_end', $options ); |
||
178 | return $options; |
||
179 | } |
||
338 |