Skip to content

Commit

Permalink
Adds Marketo script from GTM to Next Script (#431)
Browse files Browse the repository at this point in the history
* Adds Munchkin Script to Docs

* Add env based munchkin ID
  • Loading branch information
benarent authored Jan 29, 2024
1 parent 76e9cf7 commit 8493cdd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ NEXT_PUBLIC_POSTHOG_ENABLED=false
NEXT_PUBLIC_SANITY_PROJECT_ID=y1ellg96
NEXT_PUBLIC_SANITY_DATASET=production
SANITY_READ_TOKEN=""

MUNCHKIN_ID=""
31 changes: 31 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import "styles/global.css";

const NEXT_PUBLIC_GTM_ID = process.env.NEXT_PUBLIC_GTM_ID;
const NEXT_PUBLIC_GTAG_ID = process.env.NEXT_PUBLIC_GTAG_ID;
const MUNCHKIN_ID = process.env.MUNCHKIN_ID;

interface dataLayerItem {
[key: string]: unknown;
Expand All @@ -73,6 +74,36 @@ const Analytics = () => {
<Script id="add_dataLayer">
{`window.dataLayer = window.dataLayer || []`}
</Script>
{/* Munchin Script */}
{MUNCHKIN_ID && (
<>
<Script id="munchkin-script">
{`
(function() {
var didInit = false;
function initMunchkin() {
if(didInit === false) {
didInit = true;
Munchkin.init('${MUNCHKIN_ID}');
}
}
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//munchkin.marketo.net/munchkin.js';
s.onreadystatechange = function() {
if (this.readyState == 'complete' || this.readyState == 'loaded') {
initMunchkin();
}
};
s.onload = initMunchkin;
document.getElementsByTagName('head')[0].appendChild(s);
})();
`}
</Script>
</>
)}
{/* End Munchin Script */}
{/* Script for adding Qualified (https://www.qualified.com/)*/}
<Script id="script_qualified">
{`
Expand Down

1 comment on commit 8493cdd

@vercel
Copy link

@vercel vercel bot commented on 8493cdd Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.