definition( name: "UA Integration for Stairs", namespace: "Google Analytics Integration", author: "Dean Cruddace", description: "Push SmartThings device event data into Google Analytics.", category: "SmartThings Labs", iconUrl: "https://example.com/", iconX2Url: "https://example.com/yourlogo.jpg") preferences { section("When there's movement...") { input "themotion", "capability.motionSensor", title: "Where?" } } def installed() { log.debug "Installed with settings: ${settings}" initialize() } def updated() { log.debug "Updated with settings: ${settings}" unsubscribe() initialize() } def initialize() { subscribe(themotion, "motion.active", motionActiveHandler) subscribe(themotion, "motion.inactive", motionInactiveHandler) log.debug "Initialized" } def motionActiveHandler(evt) { log.debug "Motion Active" httpPost("https://www.google-analytics.com/collect","v=1&tid=UA-xx-x&cid=1&t=event&ec=Movement&ea=Motion_Sensed&el=Stairs") } def motionInactiveHandler(evt) { log.debug "Motion Inactive" httpPost("https://www.google-analytics.com/collect","v=1&tid=UA-xx-x&cid=1&t=event&ec=Movement&ea=Motion_Ceased&el=Stairs") }