diff --git a/doc/api/GUID.html b/doc/api/GUID.html new file mode 100644 index 000000000..e8548d6c8 --- /dev/null +++ b/doc/api/GUID.html @@ -0,0 +1,71 @@ + + +
+ +The GUID
Plugin adds a tracking cookie to the user that will be sent to the beacon-server as cookie
The GUID
API is encapsulated in the BOOMR.plugins.GUID
namespace
+ The GUID plugin configuration is contained in the GUID
namespace in the initial Boomerang configuration Object.
+
See "Howto #6 — Configuring boomerang" for more information on how to configure Boomerang
+ ++ Called by the BOOMR.init() method to configure the clicks plugin. +
++ BOOMR.init({ + GUID: { + cookieName: "boomerang-guid", + expires: 6000 + } + }); ++
BOOMR.init()
. See the Configuration section for details.
+
+ a reference to the BOOMR.plugins.GUID
object, so you can chain methods.
+
+ None: no beacon parameters will be set cookies will be sent in the HTTP Header +
+ ++ The latest code and docs is available on github.com/lognormal/boomerang +
+ + diff --git a/plugins/GUID.js b/plugins/GUID.js new file mode 100644 index 000000000..a3ca116cc --- /dev/null +++ b/plugins/GUID.js @@ -0,0 +1,45 @@ +/* + Tag users with a unique GUID +*/ +(function(w) { + + var impl = { + expires: 604800, + cookieName: "GUID", + generate: function() { + function s4() { + return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); + }; + + return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); + } + }; + + BOOMR.plugins.GUID = { + init: function(config) { + var properties = ["cookieName", "expires"]; + BOOMR.utils.pluginConfig(impl, config, "GUID", properties); + BOOMR.info("Initializing plugin GUID " + impl.cookieName , "GUID"); + + if(!BOOMR.utils.getCookie(impl.cookieName)) { + BOOMR.info("Could not find a cookie for " + impl.cookieName, "GUID"); + + var guid = impl.generate(); + + if (!BOOMR.utils.setCookie(impl.cookieName,guid, impl.expires)) { + BOOMR.subscribe("before_beacon", function() { + BOOMR.utils.setCookie(impl.cookieName,guid, impl.expires); + }); + } + + BOOMR.info("Setting GUID Cookie value to: " + guid + " expiring in: " + impl.expires + "s", "GUID"); + } else { + BOOMR.info("Found a cookie named: " + impl.cookieName + " value: " + BOOMR.utils.getCookie(impl.cookieName) , "GUID"); + } + return this; + }, + is_complete: function() { + return true; + } + }; +}(this));