asyncSC is an extension to the Adobe SiteCatalyst tracking library s_code.js. It brings two features to SiteCatalyst that the default implementation is sorely lacking.
-
Asynchronous loading asyncSC will manage the loading and execution of the script asynchronously and lazily. That means the s_code.js tracking library will no longer block your page load, and additionally it will only be loaded when really needed.
-
Ease of use asyncSC will make the integration of SiteCatalyst a lot easier. The script uses a consistent and easy understandable syntax, that completely hides the complicated internals of the standard SiteCatalyst tracking.
You can use asyncSC with your existing s_code.js as provided by SiteCatalyst. No changes have to be made to the script. If you have special extensions (like plugins) or settings (like Download Tracking) configured in the s_code.js they will resume working.
The basic implementation consists of few steps:
- Download asyncSC.js
- Place asyncSC.js alongside your s_code.js on you server
- Include the minimal code snippet on all pages you want to be tracked
- Change the path to the asyncSC according to your placement of the code in step 2
<!-- Standard configuration of asyncSC. A page view will be tracked. -->
<script type="text/javascript">
var _asc = _asc || [];
_asc.push(['trackPageview']);
(function(p,h,sc) {
sc=document.createElement('script');sc.type='text/javascript';sc.src=p;sc.async=1;sc.id='_ascid';
h=document.getElementsByTagName('script')[0];h.parentNode.insertBefore(sc, h);
})('/path-to-script/asyncSC.js'); // configure path to script here
</script>
Note: This setup assumes that you use the default name "s_code.js" for the SiteCatalyst Library and that it is placed in the same folder as asyncSC.js on your server. (This settings can be changed if necessary. See below.)
If your s_code.js is not hosted in the same folder as the asyncSC script, or if the script is stored under a different name you can change the setting.
// change the path to the s_code.js to "/path-to-script/s_code.js"
_asc.push(['setScodePath', '/path-to-script/s_code.js']);
By default, SiteCatalyst uses the global variable "s". If you use a different global variable the setting can be changed like this.
// change the global SiteCatalyst variable to "snew"
_asc.push(['setSCVariableName', 'snew']);
The default report suite in the script can be changed with the following command.
// set account to "new_rsid"
_asc.push(['setAccount', 'new_rsid']);
It is possible to set any SiteCatalyst custom variable.
// sets the SiteCatalyst pageName, events and prop1 variable
_asc.push(['setCustomVar', {pageName: 'Pagename', events: 'event1', prop1: 'value'}]);
By default existing variables are overwritten. This can be changed by passing false to the tracker.
_asc.push(['setCustomVar', {pageName: 'Pagename'}, false]); // will not overwrite pageName if it already exists
When triggering a page view, any variables set beforehand will be sent to SiteCatalyst.
While it is possible to send a page view without a pageName, SiteCatalyst strongly encourages to set one on every page.
// track a page view
_asc.push(['trackPageview']);
// Recommended: always set a pageName for each page view
_asc.push(['setCustomVar', {pageName: 'Pagename'}]);
_asc.push(['trackPageview']);
Click Tracking can be used to track user interactions that happen outside of the page view. Typical examples are clicks on a link or changing form elements.
asyncSC provides two different functions. Link Tracking can be used in cases where a click results in a new page beeing loaded (in the same window). Click Tracking should be used whenever the measured click doesn't result in a new page load.
This function inserts a short delay (< 500ms), to ensure, that the tracking request will be sent to SiteCatalyst before the browser loads the new page.
Link Tracking always requires a link name to be set.
// track a link click with the name "link name"
_asc.push(['trackLink', 'link name']);
Of course it is possible to pass any custom variables to the request.
// set SiteCatalyst variables
_asc.push(['setCustomVar', {events: 'event2', eVar1: 'value'}]);
// track a link click with the name "link name" and all previously set custom variables
_asc.push(['trackLink', 'link name']);
Full example
<!-- Example of a link tracking call. -->
<a href="" onclick="_asc.push(['setCustomVars', {eVar1: 'value', events: 'event2'}], ['trackLink', 'Linkname']);">Link with Tracking</a>
This function works without a delay. It is recommended to use this function wherever possible.
Click Tracking always requires a click name to be set.
// track a link click with the name "click name"
_asc.push(['trackLink', 'click name']);
Analog to the link tracking, any custom variables can be passed to the request.
// set SiteCatalyst variables
_asc.push(['setCustomVar', {events: 'event2', eVar1: 'value'}]);
// track a click with the name "click name" and all previously set custom variables
_asc.push(['trackClick', 'click name']);
It is now possible to load additional external scripts. The scripts are executed after s_code.js is loaded but before any tracking call (page view, click, ...) is made.
// load an external script
_asc.push(['loadScript', '/path-to-script/scriptname.js']);
It is possible to completely disable the tracking on individual pages.
// disable tracking for all following requests
_asc.push(['disableTracking']);
Copyright (c) 2013 DieProduktMacher GmbH.
asyncSC is licensed under GNU Lesser General Public License. You may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.