John Davidson

php - how to add google analytics code in template

0 comments
Message:


I have i one template file call abc.php and using this template only for 1 page now i want to add google conversion tracking code in section. If i add code before get_header(); function then it shows before tag and if i put after get_header(); then it shows in tag.


Please help me as i want to use conversion code only for 1 particular page so i can't add this code in header.php


 <?php
/* Template Name: Cost_Estimation_Result */
?>
<!-- Event snippet for Website lead conversion page -->
<script>
gtag('event', 'conversion', {'send_to': '*********************'});
</script>
<?php
get_header();
?>


My Answer:
You can add the Google Analytics code directly in the template file (abc.php) for the specific page where you want to track conversions. Here's how you can do it:

1. Open the abc.php file in a text editor.
2. Locate the section in the file where you want to add the Google Analytics code.
3. Add the following Google Analytics code snippet before the closing tag:

html





Replace `YOUR_GA_TRACKING_ID` with your actual Google Analytics tracking ID.

4. Save the file and upload it to your server.

By adding the Google Analytics code directly in the template file, it will only be applied to that specific page and not to other pages that use the same header template. This way, you can track conversions for that particular page without affecting other pages on your website.

Rate this post

3 of 5 based on 5049 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us