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>
// Currently only Customer.io and Fullstory support userId
gta.setUser(id, user)
gta.registerProperty(key, value)
gta.unregisterProperty(key)
All registered properties would be mixed with every events util unregister.
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'>
.
gta.registerPlugin(Plugin)
A plugin cloudn't be unregistered now, returns plugin instance.
// Set the current page, default value of the 'page' field while invoking gta.events(gtaOptions)
gta.setCurrentPage('Home Page')
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');
data-gta
property 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
key
andvalue
.
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-hash
property in DOM element use to load actions.
<script id="gta-main"
...
data-tbtracking="your actions path"
></script>
hash
is 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
- Support boot params for providers
- Add
gta.login(userId)
support - Implement
login
method on TBPanel
- Add
data-tbtracking
support
- New Plugin:
distinct id
- New provider: SensorsData
- Deferred provider loading
- Disable
displayfeatures
for Google Analytics
- Plugin
referral
andutm
will only record at first time. - Plugin
referral
andutm
now use encodeURIComponent to prevent unexpected cookie cut off.
- Plugin is able to filter event now.
- New plugin
referral plugin
gta.registerPlugin
now returns plugin's instance
- TBPanel now accepts optional
scriptUrl
- New API:
registerProvider
- Now library can be exported to
window.Gta
- Fix GTA crash when provider Baidu crash.
- New architecture
- New APIs:
(un)register(Property|Plugin)