From 711ee62b66d43f0ed4e2af42bc14c250c669df6a Mon Sep 17 00:00:00 2001 From: Peter Grippi Date: Thu, 6 Nov 2014 08:15:42 -0500 Subject: [PATCH] Add support for setting the cookie domain, name, and expiration for analytics.js --- index.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index de78cb3..ebcb970 100644 --- a/index.js +++ b/index.js @@ -4,10 +4,30 @@ var merge = require('lodash-node/compat/objects/merge'); var googleAnalyticsConfigDefaults = { globalVariable: 'ga', tracker: 'analytics.js', - webPropertyId: null + webPropertyId: null, + cookieDomain: null, + cookieName: null, + cookieExpires: null }; function analyticsTrackingCode(config) { + var gaConfig = {}; + if (config.cookieDomain != null) { + gaConfig.cookieDomain = config.cookieDomain; + } + if (config.cookieName != null) { + gaConfig.cookieName = config.cookieName; + } + if (config.cookieExpires != null) { + gaConfig.cookieExpires = config.cookieExpires; + } + + if (Object.keys(gaConfig).length === 0) { + gaConfig = "'auto'"; + } else { + gaConfig = JSON.stringify(gaConfig); + } + return [ "" ];