Jump to content

Trigger Google Analytics or Statcounter from script


Recommended Posts

I want to make a script that gives me basic stats on who is using it, and their basic info. I want to use Statcounter or Google Analytics to do the tracking. I will use a .php page on my website with only analytics/SC code in it. I am looking for the simplest way to trigger this analytics code.

Question: Is InetGet($PhpFileWithStatcounterCode, $anyLocalDir) enough to trigger statcounter code? (I am having trouble but not sure of source)

Question: Are the IE functions the next best place to look to trigger tracking code?

Thanks ahead of time chaps!

Link to comment
Share on other sites

I think it depends on your code. It sounds like it would work. I have worked with a few programs that basically listen to see if a file shows up in a directory on a machine and if it does then it grabs it and removes it from the directory and process it. Then it continues to listen to see if there is a file in the directory. Your request is a bit unclear.

 

I want to make a script that gives me basic stats on who is using it, and their basic info.

 

Are you saying you have a website that changes something in your webhosting machine and you want to listen for that change? What is the change that happens when someone is using it? how about if more than one person is using it?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Make a script that uses the _IECreate function (specifying the $f_Url & $f_visible parameters). That should do what I think you want. Of course, the user must have an internet connection for that to work. You can use this code by guinness to evaluate that - http://www.autoitscript.com/wiki/AutoIt_Snippets#IsInternetConnected

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Thanks guys, I tried forever with InetGet() function but had no success. I decided to try wget from command line as well as curl.exe to test if they triggered any stats and neither worked although both displayed the source code for stat counter.

 

I ended up using somd's method with IE, which still asks me to setup IE (not default on my computers) but it is a method that works.

_IECreate("http://www.mydomain.com/password-ok.html", 0, 0, 0, 0)

I am trying a tiny portable browser solution that uses IE as a backbone and never presents the initial IE setup. If I get that working with perhaps ShellExecute() I will post the code.

Thanks guys :)

Link to comment
Share on other sites

.. asks me to setup IE (not default on my computers) ..

I don't really understand what you're saying here. AFAIK, and I am extremely close to a 100% belief that IE need not be the 'default' browser, only that it need to be installed. Since AutoIt only works on Window's PC's (although there is a workaround for *nix PC's), and IE comes with Windows.. :mellow:

Perhaps you need to change the third parameter (*_Wait) from 0 to 1. Just a shot in the dark though..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • 1 year later...

I know this is an older topic but maybe this will help someone who is searching for an answer. What I did is incorporate the Google Analytics Measurement Protocol and Trancexx's WinHttp functions. Here's a small function that I wrote that works very well for me. It pushes an event into my GA account. With Measure Protocol you can basically push anything into GA. Just remember with Measurement Protocol, your always going to get a 200 Response back. The best way to check to see if it worked is to go into your GA account and look in the Real Time stats under Events for this function and it will show there. It only takes a second or two to show up in GA if your doing it correctly. 

#include <WinHttp.au3>

;This will push 10 events into your GA account
For $i = 1 To 10

_GA_Post("UA-xxxxxxxx-1","Autoit Test Event","Deleted",$i & " File.pdf")

Sleep(1000)

Next

;_GA_Post(Google Analytics Account ID, Event Catagory Label, Event Action Lable, Additional Lable(I used a file Name))
Func _GA_Post($GAID,$catagory,$action,$label)

$payload = "v=1&t=event&tid="& $GAID &"&cid=e3057da6-19fa-474c-aeca-23ac17475b1a&ec="& $catagory &"&ea="& $action &"%20&el="& $label
Local $gaOpen = _WinHttpOpen("Vspec Program/1.1 HTTP/5.1")
Local $gaConnect = _WinHttpConnect($gaOpen, "www.google-analytics.com")
Local $gaRequest = _WinHttpOpenRequest($gaConnect, "POST", "/collect")
_WinHttpSendRequest($gaRequest, "Content-Type:application/x-www-form-urlencoded",$payload)
_WinHttpReceiveResponse($gaRequest)

$returned = _WinHttpReadData($gaRequest)

;Close handles
_WinHttpCloseHandle($gaRequest)
_WinHttpCloseHandle($gaConnect)
_WinHttpCloseHandle($gaOpen)


EndFunc

You really need to read up on the Parameter Reference for Measurement Protocol. The CID number in the Payload Variable is very important. 

https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters

Also you can build your own hits using Google's Hit builder Tool

https://ga-dev-tools.appspot.com/hit-builder/

 

HTH

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...