function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mayank07Mayank07 

Not able to add pardot campaign tracking code in LWC

Hi Folks,
I am creating website using Lightning web component (LWC) on communities that has a number of pages.
I want to track the activities on each page using pardot tracking code. But seems like it is not possible add it directy as it contains script tags which is not allowed in LWC.
Below is the code of one of the pages:
<template>
 <div class="evencorner-bg">
 <h1 class="eventcorner_h1_c-suite">Inside Leadership</h1>
 </div>
 <div class="row">
<template for:each={leaderShipArray} for:item='item'>
 <div key={item.Id} data-id={item.Id}>
 <div class="column xscol_global">
        <img src={item.Event_Banner__c} class="largeimgcss" />
        <div class="margintopdivlarge">
        <br/> <p class="trendingvidtext">inside leadership</p>
        <br/> <p class="largeimgtextsubp1">{item.Name}</p>
        <br/> <div class="largeimgtextsubp2">{item.Short_Event_Description__c} </div>
        </div>  
        <div class="row insideleadRow">
          <div class="column insideleadCol1">
          <img src={calendarIcon} class="Icon_img" /> 
          <lightning-formatted-date-time
          value={item.Event_Start_Date__c}
          time-zone="UTC">
        </lightning-formatted-date-time>
        <span style="margin-left: 5px;">•  <lightning-formatted-date-time 
          value={item.Event_Start_Time__c} 
          hour="2-digit" 
          minute="2-digit"
          time-zone="UTC" 
          ></lightning-formatted-date-time></span>
          </div>
          <div class="column insideleadCol2">
          <a class="insideleadregbtn" href={item.DetailURL__c}>Register Now</a>
          </div>
          </div>
        </div>
 </div>
 </template>
 </div>
</template>

When i add my pardot campaign tracking code right before the </template> at the end, i get the following errors
LWC1051: Forbidden tag found in template: '<script>' tag is not allowed.
 
Invalid expression { function async_load(){ var s = document.createElement('script'); s.type = 'text/javascript'; s.src = ('https:' == document.location.protocol ? 'https://pi' : 'http://cdn') + '.pardot.com/pd.js'; var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c); } - LWC1060: Template expression doesn't allow FunctionExpression

Please help me how can add my tracking code here.
It would be great help.
​​​​​​​Thanks​​​​​​​
Best Answer chosen by Mayank07
SwethaSwetha (Salesforce Developers) 
HI Mayank,
EDIT:
I see you also posted on  https://salesforce.stackexchange.com/questions/341621/not-able-to-add-pardot-campaign-tracking-code-in-lwc.You have confirmed that adding the tracking code in Head markup of community settings fixes the issue for you.

Please consider marking this answer as best to close the thread and also help others gain better visibility to the solution that worked. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Mayank,
EDIT:
I see you also posted on  https://salesforce.stackexchange.com/questions/341621/not-able-to-add-pardot-campaign-tracking-code-in-lwc.You have confirmed that adding the tracking code in Head markup of community settings fixes the issue for you.

Please consider marking this answer as best to close the thread and also help others gain better visibility to the solution that worked. Thank you
This was selected as the best answer
Mayank07Mayank07
Thanks Swetha, it really worked for me, Additionally could you also let me know if form handler integration on communities is possible?
Ofcourse when the form is pre-built.

Regards,
Mayank