Skip to main content

Google Tag Manager

Pass data to other services through the GTM data layer

Traian avatar
Written by Traian
Updated over 2 weeks ago

This integration in only available on the Pro plan.

Please note that this is an advanced integration which assumes you're already familiar with Google Tag Manager and that you have a Google Tag Manager account already connected to your Shopify store.

Setup in Shopify

  1. Create a new custom pixel in your Shopify dashboard by navigating to Settings > Customer Events > Custom pixels > Add custom pixel

    Navigate to Customer events > Custom pixels > Add custom pixel

  2. Choose a name for the pixel - e.g. "Google Tag Manager"

  3. Copy-paste the code below into the Code section. Replace GTM-XXXXXXXX with the ID of your GTM pixel, then click Connect.

(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXXX');

analytics.subscribe("pathlight_question_viewed", event => {
window.dataLayer.push({
event: "pathlight_question_viewed",
order_id: event.customData.orderId,
customer_id: event.customData.customerId,
question_id: event.customData.questionId,
question_type: event.customData.questionType,
question: event.customData.question,
survey_id: event.customData.surveyId,
language: event.customData.language,
is_editor: event.customData.isEditor,
});
});

analytics.subscribe("pathlight_question_answered", event => {
window.dataLayer.push({
event: "pathlight_question_answered",
order_id: event.customData.orderId,
customer_id: event.customData.customerId,
question_id: event.customData.questionId,
question_type: event.customData.questionType,
question: event.customData.question,
answer_id: event.customData.answerId,
answer: event.customData.answer,
other_option_value: event.customData.otherOptionValue,
consent: event.customData.consent,
survey_id: event.customData.surveyId,
language: event.customData.language,
is_editor: event.customData.isEditor,
});
});

Setup in Google Tag Manager

  1. In Tag Manager, navigate to Triggers and click on New to create a trigger for each custom event from Pathlight.

  2. As the trigger type, scroll all the way to the bottom and select Custom Event from the Other category.

  3. For the event name enter pathlight_question_viewed (it's important you use this exact spelling, with no changes or extra spaces). Under "Trigger fires on" select Some Custom Events, then choose {{Event}} equals pathlight_question_viewed

  4. Repeat for pathlight_question_answered

Connect to Google Analytics

  1. From Tags create a new tag and select Google Analytics > Google Analytics: GA4 Event

  2. Copy-paste your measurement ID from Google Analytics and add pathlight_question_viewed as the Event Name

  3. Select Pathlight Question Viewed as the trigger

  4. Repeat the same configuration for pathlight_question_answered

Did this answer your question?