gta
gta copied to clipboard
This is the analysis tool used by teambition, aiming to simplify the use of multiple analysis services.
Analysis Tool for Teambition
Usage
First, use Bower to install GTA:
bower install gta
or with NPM:
npm install --save teambition/gta
Then, include the following script in your HTML and you are ready to go:
<script id="gta-main"
src="bower_component/gta/lib/index.js"
data-baidu="ec912ecc405ccd050e4cdf452ef4xxxx"
data-google="UA-3318xxxx-1"
data-mixpanel="77e13d08ba42fe31932a1f1418aea7b2"
data-customer="2ac3fd02efd1f9c57ae9"
data-tbtracking="your actions path"
></script>
Set User ID
// Currently only Customer.io and Fullstory support userId
gta.setUser(id, user)
Register Property
gta.registerProperty(key, value)
gta.unregisterProperty(key)
All registered properties would be mixed with every events util unregister.
Register Provider
gta.registerProvider(name, Provider, $el)
Register third party provider. $el points to element stores gta config,
it could be omitted when config stores in <script id='gta-main'>.
Register Plugin
gta.registerPlugin(Plugin)
A plugin cloudn't be unregistered now, returns plugin instance.
Set Current Page
// Set the current page, default value of the 'page' field while invoking gta.events(gtaOptions)
gta.setCurrentPage('Home Page')
Page View
Call the pageview function to record a new page view:
// Use single object
gta.pageview({
'page': '/my-overridden-page?id=1',
'title': 'my overridden page'
})
// Use multiple string
gta.pageview('/api/hello', '?world');
Events
Tips: 'page' equals to 'category' in old rules, 'type' equals to 'label' in old rules.
data-gtaproperty in DOM element use similar key-value format ({"key": "value"}) like JSON, and quota could be omitted.- Colon, comma and quota cannot be used in
keyandvalue.
You can set current page page, it will be automatically added to the gtaOptions:
// It is usually called when the route change
gta.setCurrentPage('Tasks Page')
You can call the event function to track an event:
gta.event({action: 'add content', page: 'Project Page', type: 'task', control: 'tasks layout', method: 'double-click'})
either add data-gta='event' to a DOM element as:
<button data-gta="{action: 'add content', page: 'Project Page', type: 'task', control: 'tasks layout', method: 'double-click'}">click</button>
or preloading actions to format as:
data-gta-hashproperty in DOM element use to load actions.
<script id="gta-main"
...
data-tbtracking="your actions path"
></script>
hashis the target in your acions list.
actions = [
...,
{
hash: hash
action: 'add content',
control: 'tasks layout',
type: 'task',
}
]
<button data-gta-hash="${hash}">click</button>
To automatically log gtaOptions, you can use the 'debug' mode:
gta.debug = true
or
window._gta_debug = true
Warning! old rules not supported since v0.8.0
API Documentations
Change Log
1.1.6
- Support boot params for providers
1.1.5
- Add
gta.login(userId)support - Implement
loginmethod on TBPanel
1.1.4
- Add
data-tbtrackingsupport
1.1.1 - 1.1.2
- New Plugin:
distinct id
1.1.0
- New provider: SensorsData
1.0.12
- Deferred provider loading
1.0.11
- Disable
displayfeaturesfor Google Analytics
1.0.9 - 1.0.10
- Plugin
referralandutmwill only record at first time. - Plugin
referralandutmnow use encodeURIComponent to prevent unexpected cookie cut off.
1.0.8
- Plugin is able to filter event now.
1.0.7
- New plugin
referral plugin
1.0.5 - 1.0.6
gta.registerPluginnow returns plugin's instance
1.0.4
- TBPanel now accepts optional
scriptUrl
1.0.3
- New API:
registerProvider
1.0.2
- Now library can be exported to
window.Gta
1.0.1
- Fix GTA crash when provider Baidu crash.
1.0.0
- New architecture
- New APIs:
(un)register(Property|Plugin)