This plugin helps to handle click and event tracking with google universal analytics (Read more).
You can implement your own tracking adapter, look at the implementation for Google Analytics.
This plugin uses jquery.debug so all tracking information can be easily seen in the javascript console.
The plugin supports bounce rate adjustment by sending an event in a given interval.
You can configure url parameters that should be stored in cookies and will be send on every page initialization even when the url parameters are not present. Special parameters for advertising channel and campaign are present.
bower install jquery.tracking
$.tracking({
trackBounceIntervalSeconds: 10,
sessionLifeTimeDays: 1, //sync with google analytics session lifetime
cookiePrefix: 'tracking_',
cookiePath: '.example.com',
sourceParamName: 'src',
campaignParamName: 'cmp',
storageParams: {
'src': 'organic', //source, default: organic
'cmp': 'organic' //campaign, default: organic
},
adapter: [
{
class: 'JqueryTrackingGAnalyticsAdapter'
}
]
});
$.tracking.click('my fancy link'); //sends a click event (category: button, action: click)
$.tracking.event('category', 'action', 'label', 'value', track_only_one_time=false); //sends natural event
$.tracking.conversion()
It also exposes the class JQueryTracking
for manual instantiating.
$.tracking
trackBounceIntervalSeconds: 10
sessionLifeTimeDays: 1
cookiePrefix: 'tracking_'
cookiePath: '.example.com'
sourceParamName: 'src'
campaignParamName: 'cmp'
storageParams:
'src': 'organic'
'cmp': 'organic'
adapter: [
{
class: 'JqueryTrackingGAnalyticsAdapter'
}
]
$.tracking.click('my fancy link') # sends a click event (category: button, action: click)
$.tracking.event('category', 'action', 'label', 'value', track_only_one_time = false) # sends natural event
$.tracking.conversion()
It also exposes the class JQueryTracking
for manual instantiating and extending.
Bounce rate adjustment by sending an event in a given interval.
Event
- category: bounce rate adjustment
- action: 10s | 20s | 30s | etc.
Lifetime of the cookies. Should be in sync with google analytics session time out.
Prefix for the cookies. The src
storage param will be saved in a cookie named tracking_src
.
Path for the cookies. The trailing dot means that the cookies are valid for the domain and all subdomains.
Name of the source url parameter. You can read this value via $.tracking.source
.
Name of the campaign url parameter. You can read this value via $.tracking.campaign
.
Parameters that should be stored in cookies and will be send on every page initialization even when the url parameters are not present.
storageParams:
'src': 'organic' # default organic, if no initial url param present
'cmp': 'organic' # default organic, if no initial url param present
Tracking adapters that could be loaded. You can pass you own adapter by extending the configuration:
adapter: [
{
class: 'JqueryTrackingGAnalyticsAdapter'
},
{
class: 'JqueryTrackingGTagmanagerAdapter'
},
{
class: 'JqueryTrackingFacebookAdapter'
channelName: 'fb' # -> for trackConversion, should equal
}
]
If a parameter is passed the configuration will be merged otherwise the configuration will be returned.
Track a click event. The source can be used to indicate what link was clicked.
Track an event. Read more
Return the detected channel if name undefined, sets channel otherwise.
Return the detected campaign if name undefined, sets campaign otherwise.
Track an Conversion. For details look at the adapter:
Tracks an channel event based on stored channel:
- category: advertising
- action: channel
- label: organic
Tracks an campaign event based on stored campaign:
* category: advertising
* action: campaign
* label: organic
Read the advertising channel.
Read the advertising campaign.
Calls the callback method with the google analytics anonymous id or fallback value.
Sets channel to 'paid_search' and campaign to gclid value if passed as get param.
- https://github.com/creative-workflow/jquery.tracking
- https://travis-ci.org/creative-workflow/jquery.tracking
- https://codeclimate.com/github/creative-workflow/jquery.tracking
- http://bower.io/search/?q=jquery.tracking
npm install
bower install
npm test
npm test
npm run build
- add additional data for
trackConversion
and pass to adapters
- fix typo in
getClientId
- add
doNotTrackConversion
to all adapter - introduce
JqueryTrackingGHelper
and addgetClientId
anddoGclidMatching
- make grunt-includes compatible with gulp-inlcude, no code affected
- add
doNotTrackConversion
to facebook adapter
- remove default adapter and storage params
- rename
setChannel(name)
tochannel(name)
- rename
setCampaign(name)
tocampaign(name)
- add getter mthod for
channel()
- add getter mthod for
campaign()
- dont auto track channel and campaign
- added
triggerChannelEvent
andtriggerCampaignEvent
- add new adapter JqueryTrackingFacebookAdapter and JqueryTrackingGTagmanagerAdapter
- remove per trackBounceIntervalSeconds default
- extend tests
- more comments
- fix: swap setChannel and setCampaign in bootstrap
- initial
Check out the Contributing Guidelines