Digital Data Manager is an open source library which provides the hassle-free way to integrate Digital Data Layer on your website, collect customer data with one API and send it to hundreds of tools for analytics, marketing, and data warehousing. More info at https://docs.segmentstream.com/ru.
<script type="text/javascript">
window.digitalData = {
page: {
type: "home"
},
user: {
userId: "1232321",
name: "John Dow"
},
events: []
}
</script>
<script type="text/javascript" src="segmentstream.js"></script>
<script type="text/javascript">
ddManager.initialize();
</script>
<script type="text/javascript">
(function(h,d){d=d||"cdn.segmentstream.com";var a=window.segmentstream=window.segmentstream||[];window.ddListener=window.ddListener||[];var b=window.digitalData=window.digitalData||{};b.events=b.events||[];b.changes=b.changes||[];if(!a.initialize)if(a.invoked)window.console&&console.error&&console.error("SegmentStream snippet included twice.");else{a.invoked=!0;a.methods="initialize addIntegration persist unpersist on once off getConsent setConsent".split(" ");a.factory=function(k){return function(){var c=
Array.prototype.slice.call(arguments);c.unshift(k);a.push(c);return a}};for(b=0;b<a.methods.length;b++){var f=a.methods[b];a[f]=a.factory(f)}a.load=function(a){var c=document.createElement("script");c.type="text/javascript";c.charset="utf-8";c.async=!0;c.src=a;a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(c,a)};a.loadProject=function(b){var c=window.location.search;if(0<=c.indexOf("segmentstream_test_mode=1"))try{var e=!0;window.localStorage.setItem("_segmentstream_test_mode",
"1")}catch(g){}else if(0<=c.indexOf("segmentstream_test_mode=0"))try{e=!1,window.localStorage.removeItem("_segmentstream_test_mode")}catch(g){}else try{e="1"===window.localStorage.getItem("_segmentstream_test_mode")}catch(g){}e?a.load(window.SEGMENTSTREAM_TESTMODE_INIT_URL||"https://api.segmentstream.com/v1/project/"+b+".js"):a.load(window.SEGMENTSTREAM_INIT_URL||"https://"+d+"/project/"+b+".js")};a.CDN_DOMAIN=d;a.SNIPPET_VERSION="2.0.0";a.loadProject(h)}})("<PROJECT_ID>","<CDN_DOMAIN>");
</script>
ddManager.initialize({
'integrations': {
'Google Tag Manager': {
'containerId': 'XXX'
},
'Google Analytics': {
'trackingId': 'XXX'
}
}
});
Note. You can even remove you GTM or Google Analytics tags from the code. Digital Data Manager will load them automatically.
window.ddListener.push(['on', 'event', function(event) {
if (event.name === 'Subscribed') {
console.log('event fired!');
}
}]);
window.digitalData.events.push({
'category': 'Email',
'name': 'Subscribed'
});
window.ddListener.push(['on', 'change', function(newValue, previousValue) {
console.log(newValue);
console.log(previousValue);
}]);
window.ddListener.push(['on', 'change:user.returning', function(newValue, previousValue) {
console.log(newValue);
console.log(previousValue);
}]);
window.ddListener.push(['on', 'change:cart.items.length', function(newValue, previousValue) {
console.log(newValue);
console.log(previousValue);
}]);
// user status changed to "returning"
ddManager.once('ready', function() {
digitalData.user.returning = true;
});
// new product was added to cart
ddManager.once('ready', function() {
digitalData.cart.items.push({
"id": 123,
"name": "Product 1"
});
});
Learn more at https://segmentstream.com/
The Digital Data Manager is licensed under the MIT license. See License File for more information.