javascriptwebflowsegment-io

Setting up Segment.io


I have recently finished building a website on Webflow and I am looking to integrate Segment.io onto my website to connect with different destinations. I haven't been able to figure out how I could go onto collecting event and identity data into segment.io.

I have gone on their website and have seen example scripts (as shown below) but, I can seem to figure out anywhere how I could replace the dummy from the hard-coded strings to be functional on my HTML coded website.

analytics.identify('f4ca124298', {
  name: 'Michael Bolton',
  email: 'mbolton@initech.com'
});

analytics.track('Article Bookmarked', {
  title: 'Snow Fall',
  subtitle: 'The Avalanche at Tunnel Creek',
  author: 'John Branch'
});

Is there anyone that has been successful in setting up Segment.io on their projects?


Solution

  • this code snippet goes on your web page, usually in a javascript import. Depending on how you are setting up your page, but simple javascript would be populating using the DOM values..

    The first example, using an identify call, typically happens on a form submit.

    var name = document.getElementById('name_field').value;
    var email = document.getElementById('email_field').value;
    var user_id = document.getElementById('user_id_field').value;
    
    analytics.identify(user_id, {name: name, email: email});
    
    

    Similar thinking when using the track calls..