SiteWit JavaScript v3 Documentation Tracking code Basic tracking code The base SiteWit tracking code is sw.js on SiteWit s servers at analytics.sitewit.com/sw.js and should be embedded as follows (for support of http and https protocols). The function named swpreregister is optional, but is used to register goals, transactions and persona registration upon page load. The swpreregister function must appear before the async load of the main SiteWit script. // Page Load Goal Tracking, Transaction and Persona Settings var loc = (("https:" == document.location.protocol)? "https://analytics." : "http://analytics."); document.write(unescape("%3cscript src='" + loc + "sitewit.com/v3/[account_id]/sw.js' type='text/javascript'%3e%3c/script%3e")); Persona (Unique User) tracking code Persona tracking code is used to identify a user that has been logged into or registered with the system, this is placed on pages where identifying a specific user s behavior type. This is achieved by calling the set_goal function. sw.user.set_site_unique_id('[your Unique Identifier]'); //Other Transaction or Goal Settings sw.user.set_site_unique_id('[your Unique Identifier]'); Goal tracking code Goal tracking code is used to indicate that the user has achieved a goal, this is placed in special pages or on special actions that are considered meaningful to the client. This is achieved by calling the set_goal function. //Other Transaction or Persona Settings
Transaction Code Transactions have the ability to record extra information about an order such as order id, price and quantity. A transaction is added to a page hit by calling create_transaction. The create_transaction function returns an object that can then be used to add items. Transactions can be created with or without goals, but generally a transaction happens at the same time as a goal sw.create_transaction("[order_id]","[affiliate]","[subtotal]","[tax]","[city]","[sta te]","[country]"); trans.add_item("[sku]","[name]","[category]","[price]","[quantity]"); // Other Goal and Persona Settings sw.create_transaction("[order_id]","[affiliate]","[subtotal]","[tax]","[city]","[state]"," [country]"); trans.add_item("[sku]","[name]","[category]","[price]","[quantity]"); Callback or redirection code after page, transaction or goal hit In the event that you would like to execute javascript only after the script has recorded an analytics event (page hit, transaction, goal, etc.), you can pass a function to the register_page_view method that will be called after the data has been collected. This is useful for redirects where a cancel request may stop the data from being recorded or for chaining other analytics or goal requests. Redirecting after page load (this function must be higher on the page than the main script): sw.register_page_view(function(){location.href="[url]"); After an in page goal JavaScript Trigger: sw.register_page_view([discrete or anonymous function]);
Automated Implementation Strategies There are various ways to ensure that the analytics tracking pixel is installed on every page of your site. Besides placing the tracking code into each page or using one of our various plugins, you can also have it automatically injected into every page via your web server. Below are some easy methods of implementing the tracking pixel easily for universal coverage. Apache mod_substitute If you are running your site on Apache and have the mod_substitue module installed you can easily make sure the code is delivered on every page without having to worry about changes made to files in the future or ensuring that new files have the code embedded. Simply modify your htaccess file to include the tracking pixel code before the closing </body> tag in every response. AddOutputFilterByType SUBSTITUTE text/html Substitute "s </body> #your_tracking_script_here# </body> ni" IIS.NET Master Pages If you are using a.net site with support for Master Pages then it is best to include the pixel code before the closing </body> tag in the master page. In the case of nested master pages it is only needed in the top most master pages that other master pages are inheriting. MVC Layout The approach for MVC Layout pages is similar to the Master Page implementation above. It is best to include the pixel code before the closing </body> tag in the layout page(s). 3rd Party Hosting Plugins There are plugins available for implementing the SiteWit tracking pixel into your site. These plugins work with various platforms such as WordPress, Wix, and cpanel. Partner Integrations SiteWit also has deep partner integrations with some companies such as Yola which allows for an effortless integration
Functions _sw_analytics(); Is the main SiteWit Analytics object and is returned as the oject sw. var sw = new _sw_analytics(); _sw_analytics object set_goal(int goalid) Adds a goal id to a page hit, Goal ids are generated when a user creates a goal in the SiteWit application sw.set_goal(10); register_page_view(function callback) Commits the data recorded to the SiteWit servers for processing, this should be the last function called in tracking, anything added (transaction/goal) after this call will not get recorded. sw.register_page_view(oncomplete); sw.register_page_view(function(){location.href="[url]"); create_transaction(string orderid, string affiliation, string subtotal, string tax, string city, string state, string country) Creates and returns a transaction object. sw.create_transaction("1001","affiliate","30.00","7.00","tampa","fl", "us"); hit hit is a child object of _sw_analytics (_sw_hit_info) that can be used to override the domain and page values recorded automatically by the _sw_analytics object hit.set_page(string url) Overrides the url automatically recorded by the _sw_analytics object initialization with the value passed to it. sw.hit.set_page("mypage.html");
hit.set_domain(string url) Overrides the domain automatically recorded by the _sw_analytics object initialization with the value passed to it. sw.hit.set_domain("www.sitewit.com"); user user is a child object of _sw_analytics (_sw_user_info) that can be used to set the site unique identifier. user.set_site_unique_id(string id) A unique identifier is a way for sites to uniquely identify users based on what they know about a user such as the email address of a logged in user. The unique identifier can be any string. sw.user.set_site_unique_id("user@email.com"); _sw_transaction Calling create_transaction() in the main _sw_analytics object creates and returns a _sw_transaction object. You can then add items to the new transaction object. add_item(string sku, string name, string category, string price, string quantity) Adds an item to the transaction sw.create_transaction("1001","affiliate","10.00","0.70","tampa","fl", "us"); trans.add_item("001","item1","category","1.00","10");