Third-Party Analytics | Yext Hitchhikers Platform

Adding third-party analytics (e.g. Google Analytics) requires adding a script tag to the head of your HTML documents. This is easily accomplished in Pages using the getHeadConfig export.

Process

To add an arbitrary script tag to your templates, use the other property in the HeadConfig object.

The other property is used for any content that can’t be fully encapsulated by the Tag interface. An arbitrary, user-defined string can be provided. Here is an example using a Google Analytics script tag:

export const getHeadConfig: GetHeadConfig<TemplateRenderProps> = ({
 document,
}): HeadConfig => {
 return {
   title: document.name,
   charset: "UTF-8",
   viewport: "width=device-width, initial-scale=1",
   tags: [
     {
       type: "meta",
       attributes: {
         description: "This site was generated by the Yext SSG",
       },
     },
   ],
   other: `<!-- Google tag (gtag.js) -->
   <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
   <script>
     window.dataLayer = window.dataLayer || [];
     function gtag(){dataLayer.push(arguments);}
     gtag('js', new Date());
     gtag('config', 'TAG_ID');
   </script>`
 };
};
light bulb
Note
Make sure to include your tag on every Page where you want tracking.
Feedback