This gist solves the common problem of firing a floodlight tag when you click a link. Most examples don't take into account that you can't simply fire the floodlight tag by creating a tag during the click
event. If you go with that approach, you will have a race condition where the floodlight tag may not fire successfully before the browser changes pages. To work around this issue, you have to do the following:
- Prevent the default click action of the link.
- Fire the floodlight tag, which is just a process of creating an iframe with a special URL.
- Once the floodlight tag successfully fires (
iframe.onload
), resume the normal click action.
I've done the work for you and put it into a snippet that you can insert on your page. This snippet requires no external dependencies, so it's 100% plug-and-play. The entire process takes fractions of a second, so the user shouldn't notice any lag while this is happening.
- Copy the JS above into your project.
- Change the button's ID in line #1
- Change the placeholder strings on line #5 to the floodlight tag's
source
,type
andcat
attributes found in the original floodlight tag snippet'ssrc
attribute.
Im trying to make a floodlight tag fire on form submission but I think its firing on page load. Could anyone give me some insight?
<title>OW Form</title> <script type="text/javascript"> var axel = Math.random() + ""; var a = axel * 10000000000000; document.write('<iframe src="https://4480349.fls.doubleclick.net/activityi;src=4480349;type=onewi0;cat=onewi0;dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); </script> <iframe src="https://4480349.fls.doubleclick.net/activityi;src=4480349;type=onewi0;cat=onewi0;dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe>You can view it at www.broodmethod.com/formac/