|
| 1 | +/* |
| 2 | + * JavaScript tracker for Snowplow: tag.js |
| 3 | + * |
| 4 | + * Significant portions copyright 2010 Anthon Pang. Remainder copyright |
| 5 | + * 2012-2014 Snowplow Analytics Ltd. All rights reserved. |
| 6 | + * |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are |
| 9 | + * met: |
| 10 | + * |
| 11 | + * * Redistributions of source code must retain the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer. |
| 13 | + * |
| 14 | + * * Redistributions in binary form must reproduce the above copyright |
| 15 | + * notice, this list of conditions and the following disclaimer in the |
| 16 | + * documentation and/or other materials provided with the distribution. |
| 17 | + * |
| 18 | + * * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the |
| 19 | + * names of their contributors may be used to endorse or promote products |
| 20 | + * derived from this software without specific prior written permission. |
| 21 | + * |
| 22 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | + */ |
| 34 | + |
| 35 | +/* |
| 36 | + * Use this function to load Snowplow |
| 37 | + * |
| 38 | + * @param p The window |
| 39 | + * @param l The document |
| 40 | + * @param o "script", the tag name of script elements |
| 41 | + * @param w string The source of the Snowplow script. Make sure you get the latest version. |
| 42 | + * @param i string The Snowplow namespace. The Snowplow user should set this. |
| 43 | + * @param n The new script (to be created inside the function) |
| 44 | + * @param g The first script on the page (to be found inside the function) |
| 45 | + */ |
| 46 | +;(function(p,l,o,w,i,n,g) { |
| 47 | + "p:nomunge, l:nomunge, o:nomunge, w:nomunge, i:nomunge, n:nomunge, g:nomunge"; |
| 48 | + |
| 49 | + // Stop if the Snowplow namespace i already exists |
| 50 | + if (!p[i]) { |
| 51 | + |
| 52 | + // Initialise the 'GlobalSnowplowNamespace' array |
| 53 | + p['GlobalSnowplowNamespace'] = p['GlobalSnowplowNamespace'] || []; |
| 54 | + |
| 55 | + // Add the new Snowplow namespace to the global array so sp.js can find it |
| 56 | + p['GlobalSnowplowNamespace'].push(i); |
| 57 | + |
| 58 | + // Create the asynchronous queue |
| 59 | + p[i] = function() { |
| 60 | + (p[i].q = p[i].q || []).push(arguments); |
| 61 | + }; |
| 62 | + |
| 63 | + // Create a new script element |
| 64 | + n = l.createElement(o); |
| 65 | + |
| 66 | + // Get the first script on the page |
| 67 | + g = l.getElementsByTagName(o)[0]; |
| 68 | + |
| 69 | + // The new script should load asynchronously |
| 70 | + n.async = 1; |
| 71 | + |
| 72 | + // Load Snowplow |
| 73 | + n.src = w; |
| 74 | + |
| 75 | + // Insert the Snowplow script before every other script so it executes as soon as possible |
| 76 | + g.parentNode.insertBefore(n,g); |
| 77 | + } |
| 78 | +} (window, document, 'script', '../../dist/snowplow.js', 'new_name_here')); |
0 commit comments