【问题标题】:How to find names of variabels on my own website?如何在我自己的网站上查找变量名称?
【发布时间】:2020-09-03 20:45:43
【问题描述】:

我想在我自己的网店中实现 Trustpilot javascript 扩展,以便根据访问我的结帐页面的人自动获得产品评论。

当有人访问我的 /checkout/thankyou 页面并向 Trustpilot 发送邀请时,我在 Google 跟踪代码管理器中设置了触发。他们给了我一个示例 JS 代码,用于将发明发送给 Trustpilot。我现在只停留在要发送的实际代码上……我在下面添加了示例代码。

问题:他们说...我必须用我自己的“真实变量”替换“VARIABLE_$EMAIL*”?但是我到底怎么才能找到我真正的变量名呢?

提前谢谢你,

你好,Jitske

<script> 
    document.addEventListener('DOMContentLoaded', function() {
        const trustpilot_invitation = {
            recipientEmail: 'VARIABLE_$EMAIL',
            recipientName: 'VARIABLE_$NAME',
            referenceId: 'VARIABLE_$ORDERID',
            source: 'InvitationScript',
            productSkus: 'VARIABLE_$SKU',
            products: [{
                    sku: 'VARIABLE_$SKU',
                    productUrl: 'VARIABLE_$PRODUCTURL',
                    imageUrl: 'VARIABLE_$IMAGEURL',
                    name: 'VARIABLE_$PRODUCTNAME',
                }],
        };
        tp('createInvitation', trustpilot_invitation);
    });
</script>

【问题讨论】:

  • 这是无法回答的。为此,您的网上商店必须生成可以替换其代码中占位符的值。我们不了解您的商店,因此我们不知道您的系统是否以及使用什么名称生成这些值。这是依赖于实现的,没有包罗万象的答案(如果你使用 GTM,你不需要事件处理程序,你可以只使用 DomReady 触发器)。

标签: javascript google-tag-manager trustpilot


【解决方案1】:

我从他们的支持网站上找到了this,它解释了更多需要什么。

document.addEventListener('DOMContentLoaded', function() {
    const trustpilot_invitation_data = {
        recipientEmail: 'john@gmail.com',
        recipientName: 'John',
        referenceId: 'Order_123',
        source: 'InvitationScript',
        productSkus: ['sku_1', 'sku_2'],
        products: [{
                sku: 'sku_1',
                productUrl: 'https://your_shop.com/product/1',
                imageUrl: 'https://your_shop.com/product/images/1',
                name: 'test_product_1',
            },
            {
                sku: 'sku_2',
                productUrl: 'https://your_shop.com/product/2',
                imageUrl: 'https://your_shop.com/product/images/2',
                name: 'test_product_2',
            }
        ],
    };
    tp('createInvitation', trustpilot_invitation_data);
});

所以你实际上需要从你的页面解析电子邮件和其他信息,并将其添加到这个 javascript sn-p。

【讨论】:

  • 感谢您的回答。但是问题仍然存在;如何找到与我的网页匹配的变量名称?解析就好了。
  • 嗯,这完全取决于你。意思是,要么你自己编程,要么雇人为你做。所需的值可能已经在页面本身上,因此您需要一些 javascript 代码来获取页面上已经存在的数据。最简单的方法是使用 jQuery 库并从输入字段和其他 DOM 元素中读取值。
猜你喜欢
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-30
  • 2010-12-22
  • 1970-01-01
  • 2013-12-26
相关资源
最近更新 更多