Last active
April 21, 2017 20:16
-
-
Save brucemcpherson/7453152 to your computer and use it in GitHub Desktop.
vba class for google universal analytics
This file contains hidden or 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
'[email protected] :do not modify this line - see ramblings.mcpher.com for details: updated on 1/14/2014 10:38:24 AM : from manifest:7471153 gist https://gist.github.com/brucemcpherson/7453152/raw/cUAMeasure.cls | |
Option Explicit | |
'v2.2 | |
Private pUACode As String | |
Private pBrowser As cBrowser | |
Private pID As String | |
Private pPostData As String | |
Private pUrl As String | |
Private pVersion As String | |
Private pOptOut As Boolean | |
Public Property Get UACode() As String | |
UACode = pUACode | |
End Property | |
Public Property Get id() As String | |
id = pID | |
End Property | |
Public Property Get browser() As cBrowser | |
Set browser = pBrowser | |
End Property | |
Public Function postAppView(page As String) As cUAMeasure | |
Set postAppView = Me | |
On Error GoTo failed | |
If Not pOptOut Then | |
pPostData = "v=1&tid=" & pUACode & "&cid=" _ | |
& pID & "&t=appview&an=EXCEL&av=" & pVersion & "&cd=" & page | |
pBrowser.httpPost pUrl, pPostData & "&sc=start" | |
End If | |
Exit Function | |
failed: | |
' if it ever fails then we assume tis being blocked by firewall or something and pass | |
pOptOut = True | |
End Function | |
Public Function postAppKill() As cUAMeasure | |
If Not pOptOut Then | |
pBrowser.httpPost pUrl, pPostData & "&sc=end" | |
End If | |
Set postAppKill = Me | |
End Function | |
Private Sub class_initialize() | |
Set pBrowser = New cBrowser | |
' change this to true to opt out of analytic reporting | |
pOptOut = False | |
If Not pOptOut Then | |
pUrl = "http://www.google-analytics.com/collect" | |
pID = getUserHash() | |
pUACode = getUACode() | |
pVersion = getVersion() | |
End If | |
End Sub | |
Public Sub tearDown() | |
If Not pBrowser Is Nothing Then | |
pBrowser.tearDown | |
Set pBrowser = Nothing | |
End If | |
End Sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment