成功完成API调用后,我需要触发GTM标签
我需要创建一个GTM(Google Tag Manager)标签,以便在完成API调用后触发,结果是成功(代码:200)。 单击按钮,将调用API。 我不想在Angular项目中编写任何代码(例如“将数据发送到数据层”解决方案)
我已经搜索了很多,但是我没有找到任何有用的解决方案。我真的很感谢任何答案。
I need to create a GTM (Google Tag manager) tag to be fired when an api call is done and the result is success (code: 200).
The api is called on a button click.
I don't want to write any code in my Angular project (like "sending data to the Data Layer" solution)
I have searched a lot, but I haven't found any useful solution. I would really appreciate any answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个可以使用这样的代码的帮手服务。
在构造函数中注入 googletagmanagerservice 。
现在创建一个功能,以手动触发事件。
在您的API响应之后,您可以像这样手动击中它。
示例:
PS: - 在这里,我使用了一个常数文件来管理事件和数据的字符串。
You can create one helper service in which you can have code like this.
Inject GoogleTagManagerService in the constructor.
Now create one Function for firing the event manually.
And after the response of your API, you can hit it manually like this.
Example :
PS: - Here I have used a constant file to manage strings for events and data.
使用HTTP插头可能是您的解决方案?
- > https:https://angular.io/api/api/common/common/htttp/httpptp/httpptpintperpector
- 更多解释 -
我想GTM已经添加到您的角度项目中了吗?
如果是,则可以添加拦截器。
互助器拦截每个API调用。
因此,您可以在每个API调用后都能传递所需的值,
让我们调用该文件gtm.interceptor.ts
Using the HTTP intercepter might be your solution?
-> https://angular.io/api/common/http/HttpInterceptor
-- More explanation --
I guess GTM is already added to your angular project?
If yes you can add an Interceptor.
The Intercepter intercept every single api call.
So you could pass the value of that you want after every API call
Let us call that file gtm.interceptor.ts