Created
December 13, 2016 09:01
-
-
Save beevelop/411813144f0a5e3856da2adb7a45c823 to your computer and use it in GitHub Desktop.
ng-cordova: cordovaGoogleAnalytics for danwilson's google-analytics-plugin v1.7.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('foobar.analytics', []) | |
.factory('$googleAnalytics', [ '$q', '$window', function ($q, $window) { | |
return { | |
startTrackerWithId: function (id, dispatchPeriod) { | |
var d = $q.defer(); | |
$window.ga.startTrackerWithId(id, dispatchPeriod, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
setAllowIDFACollection: function (allowIDFACollection) { | |
var d = $q.defer(); | |
$window.ga.setAllowIDFACollection(allowIDFACollection, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
setUserId: function (id) { | |
var d = $q.defer(); | |
$window.ga.setUserId(id, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
setAnonymizeIp: function (anonymize) { | |
var d = $q.defer(); | |
$window.ga.setAnonymizeIp(anonymize, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
setOptOut: function (optout) { | |
var d = $q.defer(); | |
$window.ga.setOptOut(optout, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
setAppVersion: function (version) { | |
var d = $q.defer(); | |
$window.ga.setAppVersion(version, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
debugMode: function () { | |
var d = $q.defer(); | |
$window.ga.debugMode(function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
trackMetric: function (key, value) { | |
var d = $q.defer(); | |
$window.ga.trackMetric(key, value, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
trackView: function (screen, campaingUrl, newSession) { | |
var d = $q.defer(); | |
$window.ga.trackView(screen, campaingUrl, newSession, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
addCustomDimension: function (key, value) { | |
var d = $q.defer(); | |
var parsedKey = parseInt(key, 10); | |
if (isNaN(parsedKey)) { | |
d.reject('Parameter "key" must be an integer.'); | |
} | |
$window.ga.addCustomDimension(parsedKey, value, function () { | |
d.resolve(); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
trackEvent: function (category, action, label, value, newSession) { | |
var d = $q.defer(); | |
$window.ga.trackEvent(category, action, label, value, newSession, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
trackException: function (description, fatal) { | |
var d = $q.defer(); | |
$window.ga.trackException(description, fatal, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
trackTiming: function (category, milliseconds, variable, label) { | |
var d = $q.defer(); | |
$window.ga.trackTiming(category, milliseconds, variable, label, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
addTransaction: function (transactionId, affiliation, revenue, tax, shipping, currencyCode) { | |
var d = $q.defer(); | |
$window.ga.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
addTransactionItem: function (transactionId, name, sku, category, price, quantity, currencyCode) { | |
var d = $q.defer(); | |
$window.ga.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
}, | |
enableUncaughtExceptionReporting: function (enable) { | |
var d = $q.defer(); | |
$window.ga.enableUncaughtExceptionReporting(enable, function (response) { | |
d.resolve(response); | |
}, function (error) { | |
d.reject(error); | |
}); | |
return d.promise; | |
} | |
}; | |
} ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment