AnalyticsTracker is a utility aimed at making it easier to track data from ASP.NET applications to Google Analytics and Google Tag Manager - GitHub ...
Skiptocontent
{{message}}
mortenbock
/
AnalyticsTracker
Public
Notifications
Fork
7
Star
5
AnalyticsTrackerisautilityaimedatmakingiteasiertotrackdatafromASP.NETapplicationstoGoogleAnalyticsandGoogleTagManager
License
MITlicense
5
stars
7
forks
Star
Notifications
Code
Issues
0
Pullrequests
0
Actions
Projects
0
Wiki
Security
Insights
More
Code
Issues
Pullrequests
Actions
Projects
Wiki
Security
Insights
mortenbock/AnalyticsTracker
Thiscommitdoesnotbelongtoanybranchonthisrepository,andmaybelongtoaforkoutsideoftherepository.
master
Branches
Tags
Couldnotloadbranches
Nothingtoshow
{{refName}}
default
Couldnotloadtags
Nothingtoshow
{{refName}}
default
3
branches
11
tags
Code
Latestcommit
Gitstats
46
commits
Files
Permalink
Failedtoloadlatestcommitinformation.
Type
Name
Latestcommitmessage
Committime
packaging
src
tools/NuGet
.gitignore
AnalyticsTracker.sln
LICENSE
README.md
Viewcode
WelcometoAnalyticsTracker
Installation
GoogleAnalytics
MVC
Webforms
Advancedtrackersettings
Ajax
Usage
Overrideurl
Commands
Ecommercetracking
EnhancedEcommercetracking
Trackonlyonce
Clientsidetracking
GoogleTagManager
MVC
Webforms
Renderingindividualparts
Advancedtrackersettings
Usage
Complexvariables
Ecommerceordertracking
README.md
WelcometoAnalyticsTracker
AnalyticsTrackerisautilityaimedatmakingiteasiertotrackdatafromASP.NETapplicationstoGoogleAnalyticsandGoogleTagManager
GoogleAnalytics
GoogleTagManager
Installation
InstallingAnalyticsTrackerissimple.InstallitfromNuGettoaddittoyourproject.
GoogleAnalytics
Inyourtemplate,addthefollowingafterthe
torenderthetrackingscript
MVC
@usingVertica.AnalyticsTracker
...
@AnalyticsTracker.Render("UA-xxxxxx-1")
...
Webforms
...
...
Advancedtrackersettings
YoucantweakthesettingsofthetrackerbyusingtheoverloadsoftheRender()method.
@AnalyticsTracker.Render(
account:"UA-xxxxxx-1",
trackDefaultPageview:true,
displayFeatures:false,
trackerConfiguration:newDictionary
{
{"cookieDomain","foo.example.com"},
{"cookieName","myNewName"},
{"cookieExpires",20000}
});
Ajax
AnalyticsTrackercanalsotrackdatafromajaxrequests.Inordertoactivatethis,addtheVertica.AnalyticsTracker.Modules.AnalyticsHttpModuletoyourapplication.Thenforrequestsyouwanttotrack,settheAnalyticsTracker-Enabledhttprequestheadertotrue.
Theresponsewillthenincludethetrackingjscodeasbase64encodedheaders.
WehaveincludedajaxinterceptorsforjQueryandangularinthefile/Scripts/analyticstracker.adapters.js,thatyoucanincludeinyousite.Makesuretoincludeitaftertheframeworks.
Usage
AnalyticsTrackeraimstoprovidesomsensibledefaults,andletyouoverridesomeoftheadvancedsettingsifyouneedto.
Overrideurl
Ifyouwanttotrackadifferenturlforthepageviewthantheoneinthebrowser,youcanoverrideitbysettingthepageofthecurrenttracker
AnalyticsTracker.Current.SetPage("/my/custom/url");
Commands
BydefaultAnalyticsTrackerwilloutputthebasictrackingcode,andtrackastandardpageview.Whenyouwanttotrackadditionaldata,youaddcommandstothecurrenttracker.
Herewearetrackinganeventfromacontroller
publicActionResultAbout()
{
AnalyticsTracker.Current.Track(newEventCommand("category","action","label"));
ViewBag.Message="Yourapplicationdescriptionpage.";
returnView();
}
Ecommercetracking
Thecommandtotrackanecommercetransactioncanbeusedlikethis:
vartransaction=newTransactionInfo(
id:"order1001",
affiliation:string.Empty,
revenue:100,
shipping:10,
tax:5,
currency:AnalyticsCurrency.USD);
transaction.AddItem(
name:"Blackshirt",
sku:"sh001",
category:"Shirts",
price:50,
quantity:2);
AnalyticsTracker.Current.Track(newTransactionCommand(transaction));
EnhancedEcommercetracking
IfyouhaveenabledEnhancedEcommercetrackinginyouraccount,thenyoushouldusethosecommandstotrackyourtransactions:
varpurchaseAction=newPurchaseActionFieldObject(
id:"order1001",
affiliation:string.Empty,
revenue:100,
shipping:10,
tax:5,
coupon:null);
varlineItems=new[]
{
newProductFieldObject(
id:"sh001",
name:"Blackshirt",
brand:"Northwind",
category:"Shirts",
variant:null,
price:50,
quantity:2,
coupon:null,
position:1)
};
AnalyticsTracker.Current.Track(newPurchaseCommand(purchaseAction,lineItems));
Youmayalsowanttosetthecurrencyonyourtrackerwhentrackingecommerce
EnhancedEcommercealsoletsyoutrackalotofotherthings.ThecommandsarelocatedintheVertica.AnalyticsTracker.Commands.EnhancedEcommercenamespace:
AddToBasketCommand(...)
RemoveFromBasketCommand(...)
CheckoutCommand(...)
CheckoutOptionCommand(...)
ProductClickCommand(...)
ProductDetailCommand(...)
ProductListCommand(...)
Trackonlyonce
Atypicalthingyouwanttodoistomakesurethatforexampletransactionsareonlytrackedonce,eveniftheuserreloadsthepage.Youshouldkeeptrackofthisfromyourserver,buttherewilltypicallyalsobetheissueofusersusingthebackbutton,orbrowsersrehydratingapageetc.wherethereisnoactualserverinteraction.
EntertheCookieGuardedCommand:
AnalyticsTracker.Current.Track(newCookieGuardedCommand(innerCommand,"order12345"));
WrappingyourcommandinaCookieGuardedCommandwillrendertheinnercommandinsideanifstatementlikethis:
if(document.cookie.search(/AnalyticsTrackerGuardorder12345=true/)===-1){
ga('send',{'hitType':'event','eventCategory':'cat','eventAction':'act','eventLabel':''});
document.cookie='AnalyticsTrackerGuardorder12345=true;Expires='+newDate(2016,05,02).toUTCString();
}
Thiswillensurethatthecommandisnotexecutedagain,ifthesamejavascriptisexecutedtwice.Userforexampletheorderidasthecommandidtomakesurethatthecookieisonlysetforthatspecificorder.
Clientsidetracking
Sometimesyouhaveeventshappeningwithoutanyserverinteraction.Forexampleclickingonanimagetozoomit.InthiscaseyoucanuseAnalitycsTrackertogeneratetheneededscript:
GoogleTagManager
Inyourtemplate,addthefollowingafterthetorenderthetrackingscript
MVC
@usingVertica.AnalyticsTracker
...
@TagManager.Render("GTM-XXYYY")
...
Webforms
...
...
Renderingindividualparts
IfneedbeyoucanrendertheindividualpartsofGoogleTagManager(script,noscriptanddatalayer)with:
TagManager.RenderScript()
TagManager.RenderNoScript()
TagManager.RenderDataLayer()
Advancedtrackersettings
YoucantweakthesettingsofthetagbyusingtheoverloadsoftheRender()method.
@TagManager.Render(account:"GTM-XXYYY",dataLayerName:"myLayer");
Usage
UsingtheTagManagerletsyoueasilyinformationtothedataLayervariable.
TagManager.Current.AddMessage(newVariable("myVariable","myValue"));
ThiswillgeneratethefollowingdataLayer
Complexvariables
SometimesyoumightwanttoaddmorecomplexobjectstothedataLayer,andthisissupportedbyusingadictionary
vardict=newDictionary
{
{"myProp","myValue"},
{"yourProp",12345}
};
TagManager.Current.AddMessage(newVariable("myVariable",dict));
Thedictionarywillthenberenderedasadeepobject
Ecommerceordertracking
UsingtheTransactionMessage,orderinformationcanbesentthroughthedataLayer:
varitems=new[]
{
newTransactionItemInfo(
name:"Blackshirt",
sku:"sh001",
category:"Shirts",
price:50,
quantity:2)
};
varmessage=newTransactionMessage(
transactionId:"order1001",
affiliation:string.Empty,
total:100,
tax:5,
shipping:10,
items:items);
TagManager.Current.AddMessage(message);
TheorderwillberenderedaccordingtotheGTMspecifications:
About
AnalyticsTrackerisautilityaimedatmakingiteasiertotrackdatafromASP.NETapplicationstoGoogleAnalyticsandGoogleTagManager
Topics
aspnet
google-analytics
google-tag-manager
Resources
Readme
License
MITlicense
Stars
5
stars
Watchers
8
watching
Forks
7
forks
Releases
10
v2.0.4
Latest
Apr26,2018
+9releases
Packages0
Nopackagespublished
Contributors6
Languages
C#
96.2%
JavaScript
3.5%
Batchfile
0.3%
Youcan’tperformthatactionatthistime.
Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession.
Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.