diff --git a/bower.json b/bower.json index 4d08e40..b6c13e8 100644 --- a/bower.json +++ b/bower.json @@ -1,8 +1,9 @@ { "name": "angulartics-segment", "main": "./dist/angulartics-segment.min.js", + "version": "0.2.0", "dependencies": { - "angulartics": "^1.0.2" + "angulartics": "^1.1.0" }, "ignore": [ "**/.*", diff --git a/lib/angulartics-segment.js b/lib/angulartics-segment.js index 0816436..f0548b1 100644 --- a/lib/angulartics-segment.js +++ b/lib/angulartics-segment.js @@ -8,71 +8,77 @@ angular.module('angulartics.segment', ['angulartics']) .config(['$analyticsProvider', function ($analyticsProvider) { - // https://segment.com/docs/libraries/analytics.js/#page - // analytics.page([category], [name], [properties], [options], [callback]); - // TODO : Support optional parameters where the parameter order and type changes their meaning - // e.g. - // (string) is (name) - // (string, string) is (category, name) - // (string, object) is (name, properties) - $analyticsProvider.registerPageTrack(function (path, properties) { - try { - // only pass `path`, segment script will automatically populate properties - analytics.page(path); - } catch (e) { - if (!(e instanceof ReferenceError)) { - throw e; + // This allows users to load their segment library async, queue events, + // and send them whenever the script is ready + angulartics.waitForVendorApi("analytics", 1000, "initialized", registerHandlers); + + function registerHandlers(){ + // https://segment.com/docs/libraries/analytics.js/#page + // analytics.page([category], [name], [properties], [options], [callback]); + // TODO : Support optional parameters where the parameter order and type changes their meaning + // e.g. + // (string) is (name) + // (string, string) is (category, name) + // (string, object) is (name, properties) + $analyticsProvider.registerPageTrack(function (path, properties) { + try { + // only pass `path`, segment script will automatically populate properties + analytics.page(path); + } catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } } - } - }); + }); - // https://segment.com/docs/libraries/analytics.js/#track - // analytics.track(event, [properties], [options], [callback]); - $analyticsProvider.registerEventTrack(function (event, properties, options, callback) { - try { - analytics.track(event, properties, options, callback); - } catch (e) { - if (!(e instanceof ReferenceError)) { - throw e; + // https://segment.com/docs/libraries/analytics.js/#track + // analytics.track(event, [properties], [options], [callback]); + $analyticsProvider.registerEventTrack(function (event, properties, options, callback) { + try { + analytics.track(event, properties, options, callback); + } catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } } - } - }); + }); - // https://segment.com/docs/libraries/analytics.js/#identify - // analytics.identify([userId], [traits], [options], [callback]); - $analyticsProvider.registerSetUserProperties(function (userId, traits, options, callback) { - try { - analytics.identify(userId, traits, options, callback); - } catch (e) { - if (!(e instanceof ReferenceError)) { - throw e; + // https://segment.com/docs/libraries/analytics.js/#identify + // analytics.identify([userId], [traits], [options], [callback]); + $analyticsProvider.registerSetUserProperties(function (userId, traits, options, callback) { + try { + analytics.identify(userId, traits, options, callback); + } catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } } - } - }); + }); - // https://segment.com/docs/libraries/analytics.js/#identify - // analytics.identify([userId], [traits], [options], [callback]); - $analyticsProvider.registerSetUserPropertiesOnce(function (userId, traits, options, callback) { - try { - analytics.identify(userId, traits, options, callback); - } catch (e) { - if (!(e instanceof ReferenceError)) { - throw e; + // https://segment.com/docs/libraries/analytics.js/#identify + // analytics.identify([userId], [traits], [options], [callback]); + $analyticsProvider.registerSetUserPropertiesOnce(function (userId, traits, options, callback) { + try { + analytics.identify(userId, traits, options, callback); + } catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } } - } - }); + }); - // https://segment.com/docs/libraries/analytics.js/#alias - // analytics.alias(userId, previousId, options, callback); - $analyticsProvider.registerSetAlias(function (userId, previousId, options, callback) { - try { - analytics.alias(userId, previousId, options, callback); - } catch (e) { - if (!(e instanceof ReferenceError)) { - throw e; + // https://segment.com/docs/libraries/analytics.js/#alias + // analytics.alias(userId, previousId, options, callback); + $analyticsProvider.registerSetAlias(function (userId, previousId, options, callback) { + try { + analytics.alias(userId, previousId, options, callback); + } catch (e) { + if (!(e instanceof ReferenceError)) { + throw e; + } } - } - }); + }); + } }]); diff --git a/package.json b/package.json index 0d6d759..e87180f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angulartics-segment", - "version": "0.1.5", + "version": "0.2.0", "description": "Segment plugin for Angulartics", "keywords": [ "segment", @@ -32,7 +32,7 @@ }, "license": "MIT", "peerDependencies": { - "angulartics": "^1.0.0" + "angulartics": "^1.1.0" }, "devDependencies": { "uglify-js": "^2.4.23"