I was able to find a solution after trying multiple things. I just had to put the javascript code from google analytics between a php if
condition like this:
<?php if (cn_cookies_accepted()) { ?> <script type="text/javascript"> (function(i,s,o,g,r,a,m).{i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-#', 'auto'); ga('set', 'forceSSL', true); ga('set', 'anonymizeIp', true); ga('send', 'pageview'); </script> <?php } ?>
Related Posts:
- How to extend WordPress Bookly plugin
- php, cookies, wordpress – how to make automatic login in one one site, login and on other one
- WordPress Login Tracking Google Analytics
- How to enable button onClick functions and java script in wordpress post
- How to add custom javascript to WordPress Admin?
- How can i Toogle between 2 icons without reloading page in wordpress
- validate textfield contents in wordpress simple job board plugin
- wordpress Simple Job board plugin hide cv attachment form
- W3 Total Cache WordPress plugin disturbing my page layout
- WordPress Error: There has been a critical error on your website. Please check your site admin email inbox for instructions
- How do i give a WordPress editor access to the Site Kit by Google plugin?
- How to define custom capabilities in wordpress for custom plugin
- Why can’t import backup site WordPress? Plugin All-in-one migration
- function “add_submenu_page in wordpress connects to the home page instead of the submenu page
- Redirect after Login on WordPress
- Formidable Forms WordPress Plugin
- JS Manga Reader with WordPress NoConflict JQuery
- Redirect old php link to wordpress link in .htaccess
- Redirect old php link to wordpress link in .htaccess
- WordPress qw.php file on root of installation
- Remove “Protected” text in title h1 of protected wordpress pages
- How to convert JPG to PNG on upload in WordPress (via add_image_size)?
- WordPress asking for my FTP credentials to install plugins
- What is the meaning of ‘OFFSET’ => 1 (WordPress)
- Display only one category on home page wordpress
- WordPress custom thumbnail size
- WordPress custom thumbnail size
- Local WordPress installation is stripping ‘wp-admin’ from URL on WordPress admin dashboard
- Elements wont play when combine javascript in wordpress with wp-rocket
- Random Question Mark Icons In WordPress Text
- Creating a custom rebrandly link using a wordpress shortcode
- WordPress thumbnail cropping not working
- Flaticons not showing up on WordPress
- What does arg mean in WordPress
- How to use wp_enqueue_style() in my WordPress theme?
- Unable to manage Google AdSense with Adspro WordPress Plugin
- Query multiple WordPress post types alternately
- About 404 during WordPress installation
- “The Events Calendar” plugin by Modern Tribe in WordPress not working
- After moving WordPress, login works, but no admin access anymore
- WordPress Main Menu – Hide ‘Home’ link on homepage only
- Speech recognition in WordPress based on Alexa Skill
- Why am I getting 404 not found on this wordpress subdomain on my Nginx server?
- WordPress get_terms() function not display custom taxonomy categories for woocommerce
- Advanced Custom Fields, WordPress, Javascript Tabbed Content
- Scalable wordpress setup
- How to display WordPress search results?
- WordPress – Display Random Number Between 190-250
- WordPress plugin (Q&A Lite by WPMU Dev) not working once logged out from the WordPress admin account
- How to set on load marathi language using google translator in wordpress?
- Double slashes on WordPress Admin URL redirects to wp-login
- I have shifted my wordpress site from one host to another, after shift the website wp-admin is not open
- How to use If, If Else and else in WordPress
- Display Ninja Forms Data in WordPress Template
- Enable “Post Formats” Just For a “Custom Post Type” And Not Others In WordPress
- How can I embed a YouTube video in a WordPress template page?
- Embed podcast feed in wordpress
- Modern Events Calendar & WordPress: Advanced Speaker addon’s Speaker single page summary doesn’t recognize paragraph breaks
- wordpress add_query_arg how to add multiple queries to URL
- Custom Coupon type woocommerce wordpress
- WordPress home page is blank but every other page is working fine
- How to use wp-ajax in wp-cron
- Creating an Exit Confirmation Popup
- Pass a php string to a javascript variable
- wordpress site | All-in-one-cufon IE Issue
- How to get the element ID from new menu list that added with add_filter()?
- Override Plugin Script Fucnction in WordPress
- How to insert HTML/JavaScript form into WordPress page? [closed]
- How to get my plug-in, wrote in php, to refresh on its own every 5 minutes?
- Using window.onload with Ubermenu
- wordpress add_action() issue in ajax call
- Pass user role to javascript code inside body
- How to get specific string/value from an array? php [closed]
- Background Music WP [closed]
- Social share buttons text shows up on post excerpts
- Plugin Admin panel checkbox unchecked after submit
- Custom Plugin scripts from admin working in frontend
- Ajax call not working in wordpress through a plugin
- Send Array from JS to php file then insert it in wp database through a plugin
- Cookie value changes back to previous value after changing
- Possible way of having multiple Gutenberg instances for a page?
- Woocommerce add products to cart
- Why does my custom plugin only function correctly once per page?
- How to get a specific string from a url
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- How to use Datatable with Ajax when creating plugin on WordPress?
- Problem with wordpress has_action() function
- Woocommerce – Change variations output
- WordPress load javascript file if something… (after the page is loaded)
- Conditional Fields depending on checkboxes
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- How to create a dashboard for logged-in users with custom functionality? [closed]
- Creating a user ‘add custom field’ section
- Media Playlist Plugin
- How do I convince this button to do something when it is clicked?
- Undefined constant error in pluggable.php
- How to create post comparison in wordpress
- Losing Session ID and sessionStorage when navigating to other domains on Multisite
- how to show selected options drop down menu values in attributes field in after saving post.php
- Refresh server side rendered block in Gutenberg without changing attributes or its content