Tracking custom IFRAME events in Google Tag Manage

2019-02-19 00:39发布

问题:

I have some IFRAMEs on my pages for external services -- AddThis, YouTube, and a JWPlayer-based custom video solution. I want to use GTM to track clicks and responses in those IFRAMEs (particularly 'play' events on the video) but the cross-domain policy prevents that. How do I make that work -- and how do I get it to work in GTM?

回答1:

It took me a while to figure it out, but basically:

  • Create a GTM container and add the GTM codeblock to pages on your site.
  • Create a ‘Tag’ to be your event listener.
  • Create two ‘Triggers’: one for which pages to listen for the event, and one that fires when your event happens.
  • Create one or more ‘Variables’ to store the info from your event listener ‘Tag’
  • Create another ‘Tag’ to take the info you stored in the ‘Variables’ and pass it to Google Analytics.
  • Go into the Google Analytics console and watch the events come in.

I wrote up a more complete, long-form guide at http://ieg.wnet.org/blog/using-google-tag-manager-for-custom-event-tracking/