npm install
grunt
grunt watch
<head>
<script src="dist/tracker.js"></script>
</head>
<body>
<script type="text/javascript">
// Set your options
var opt = {
clientId: '1234asdf',
pageType: 'Article',
pageId: '98798342'
}
// Create your activity. It needs your options as a parameter.
var activity = new Activity(opt);
// When you have your activity, you can track an event
activity.events.trackPageLoad('Test article', 'Read').send();
</script>
</body>
// Set your options
var opt = {
clientId: '1234asdf',
pageType: 'Article',
pageId: '98798342'
}
// Create your activity. It needs your options as a parameter.
var activity = new Activity(opt);
// Use .queue() to add events to the queue.
activity.events.trackComment('843223', 'Post').queue();
activity.events.trackPoll('843223', 'Post').queue();
// And manually send the queue.
activity.sendQueue();
// Set your options
var opt = {
clientId: '1234asdf',
pageType: 'Article',
pageId: '98798342'
}
// Create your activity. It needs your options as a parameter.
var activity = new Activity(opt);
// Use .queue() to add events to the queue.
activity.events.trackComment('843223', 'Post').addCustomData('primary', {words: 32, lines: 3}).send();
activity.events.trackPoll('843223', 'Post').addProperty('secondary', 'displayName', 'Is this a question?').send();
primary
, secondary
and tertiary
is used to tell which object you want to add data to. Each event function described below has specified the objects being generated and which reference the object coresponds with.
opts = {
pageId: '', // The Id of the current page/article (required)
clientId: '', // The providers ID, supplied by SPT. (required)
pageType: '', // The type of page where the Activity is created. Default 'Page'
url: '', // The URL that data will be sent to.
transport: f() // To specify custom transport function.
provider: {} // Add custom provider data
}
Used for login / logout events. When a user logs in, call this function with a user ID in the following format:
urn:<your domain>:user:<your userId>
. When the user logs back out, call the same function with undefined
.
title
- The title of the page. Will default to document.title
activityType
- The type of activity that is being tracked. Will default to 'Read'
object
as 'primary'
- Where the event originated.
content
store the content of the submitted form.
formId
- The ID of the form element, must be unique per page.
contentType
- The type of content generated by the form (note, spt:email, other? )
activityType
- The type of activity that is being tracked. Will default to 'Post'
object
as 'primary'
- The object of the Activity. In this case, the form.
result
as 'secondary'
- The result of the event. In this case, some new content from the form.
origin
as 'tertiary'
- Where the Activity originated (e.g the page)
displayName
- The title of the form in a human readable format.
content
store the content of the submitted form.
inReplyTo
a string or a object that links the this form submission to a some other entity.
url
A URL will be set automatically using document.URL, but if you are running a single page application or for some other reason want to change the URL, feel free to do so.
formId
- The ID of the form element, must be unique per page.
activityType
- The type of activity that is being tracked. Will default to 'Post'
object
as 'primary'
- The object of the Activity. In this case, the form.
result
as 'secondary'
- The result of the event. In this case, some new content from the form.
origin
as 'tertiary'
- Where the Activity originated (e.g the page)
content
- store the content of the comment.
inReplyTo
- a string or a link object that links this comment to a page/article or another comment.
spt:commentId
- The ID of the comment being generated by the comment form
formId
- The ID of the form element, must be unique per page.
activityType
- The type of activity that is being tracked. Will default to 'Post'
object
as 'primary'
- The object of the Activity. In this case, the form.
result
as 'secondary'
- The result of the event. In this case, some new content from the form.
origin
as 'tertiary'
- Where the Activity originated (e.g the page)
question
- The question being asked, will be stored in displayName in primary object.
oneOf
- A object in the object
with @type
'collection' and items
property with a array of possible answers.
replies
- A object in the result
with @type
'collection' and items
property with a array of answers.
elementId
- The ID of the clicked element.
displayName
- The name/title of the clicked element.
targetType
- The type of entity that is the target for the action (page, application, process, article)
targetId
- The ID of the target.
activityType
- The type of activity that is being tracked. Will default to 'Accept'
object
as 'primary'
- Where the event originated. In this case, the clicked element.
target
as 'secondary'
- The target of the action. Normally the current page or where a users ends up after the action.
displayName
To get a good textual representation. Can be used for both primary and secondary object.
elementId
- The ID of the button or link the user clicks to achieve a social action (e.g Facebook like button)
networkName
- The name of the social network. (Facebook, Twitter, Pintrest etc.)
activityType
- The type of activity that is being tracked. Will default to 'Like'
object
as 'primary'
- The page/article/entity being shared/liked.
origin
as 'secondary'
- Where the event happened, such as a button or link.
target
as 'tertiary'
- The target of the action. The socialmedia site receiving the action.
displayName
To get a good textual representation. (for all objects)
mediaId
- The ID of the media entity.
mediaType
- The type of media (video, audio, album)
activityType
- The type of activity that is being tracked. Will default to 'Watch'
object
as 'primary'
- The media entity where a state change happened.
origin
as 'secondary'
- The page where the event was generated.
displayName
To get a good textual representation.
url
The URL to the page.
scrollDepth
- A value representing the relative scroll distance. Will be stored as a content parameter in the target.
activityType
- The type of activity that is being tracked. Will default to 'Arrive'
object
as 'primary'
- The page or entity where scroll happened.
target
as 'secondary'
- The scroll depth.
displayName
- A human readable text for the scroll distance (e.g "Under header")(for target
)
elementId
- The ID of the element that are tracked.
elementId
- Either a string with start time as a AS 2.0 compatible timestamp, or a object {start: , end: <timestamp}
activityType
- The type of activity that is being tracked. Will default to 'Arrive'
origin
as 'primary'
- The page or entity where the element is located.
object
as 'secondary'
- The element that is tracket.
displayName
- A human readable text for the element.
If no target is available, set targetId and targetType to undefined.
targetId
- The ID of where the user goes next.
targetType
- The type of the target for the users exit (page, article, application)
activityType
- The type of activity that is being tracked. Will default to 'Leave'
object
as 'primary'
- The page or entity where exit happened.
target
as 'secondary'
- Target action for the exit, for example the next page.
displayName
- A human readable text such as a title or description.
duration
- A integer representing the number of milliseconds that the engagement has lasted.
activityType
- The type of activity that is being tracked. Will default to 'View'
object
as 'primary'
- The page or entity the engagement is taking place.
displayName
- A human readable text for the scroll distance (e.g "Under header")(for target
)
A function for tracking any other events. Takes an object with Activitystream 2.0 compatible objects. Actor and header info will be added by the function.
obj
- A object of Activitystream 2.0 objects (like object, target and origin).
activityType
- The type of activity that is being tracked. No default
object
- The target object in the activity (object, target, result, origin etc).
property
- The property that should be added. Allowed properties: http://www.w3.org/TR/2015/WD-activitystreams-vocabulary-20150129/#properties '4. Properties'
value
- Preferably a string, but an objects will work as well. If a raw Activitystream object is inputed, it can compromise future compatibility.
object
- The target object in the activity (object, target, result, origin etc).
data
- An object. All data will be a sub-object of the property spt:custom
. All property values in the data
object should be prefixed with spt:
Will ship the built event objects to the Activity object to get providor and actor, before it gets sent to the server.
Will add the created activity to a queue to be sent later.