提问人:Ayush Sachan 提问时间:11/9/2023 更新时间:11/9/2023 访问量:25
NextJS:Google Ads 广告系列事件在 localhost 中触发,但不在生产中触发
NextJS: Google Ads campaign event triggered in localhost but not in production
问:
我已经将脚本添加到layout.tsx
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ADS_CONVERSION_ID}`}
></script>
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ADS_CONVERSION_ID}',{
page_path: window.location.pathname,
});
`,
}}
/>
在另一个文件中,当用户提交表单时,将触发此事件。
if (response.status === 200) {
if (typeof window.gtag === "function") {
// Fire Google Ads conversion tracking
// console.log("Sending conversion tracking event to Google Ads");
console.log("hueeeeeeeeee");
window.gtag("event", "conversion", {
send_to: `${process.env.NEXT_PUBLIC_GOOGLE_ADS_CONVERSION_ID}/VvgeCJ6fuvIYEL6kjbkq`,
event_callback: () => {
console.log("Conversion event tracked!");
},
});
}
在 localhost 中,这是在控制台中打印的
hueeeeeeeeeee
Conversion event tracked!
但是在 Vercel 上部署的 prod 中,只有这个是在控制台中打印的
hueeeeeeeeeee
答: 暂无答案
评论