Skip to content

How to give Dynamic values to data layer parameters #71

Description

@jayakumarim

Hi All,
I want to give data layer parameters dynamically to each page route in angular.
I add bellow script in tag of index.html.

<script> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ appId: 'UR_REP', pageName: 'test', hostEnv: 'Dev', product: 'OPAY' }); </script>

And i push new values for every page route like below

this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
ga('set', 'page', event.urlAfterRedirects);
ga('send', 'pageview');
const currentDataLayer = {
appId: 'UR_REP',
pageName: event.id + '',
hostEnv: 'Dev' + event.id,
product: 'Opay' + event.id
};
window.dataLayer.push(currentDataLayer)
}
});

But it's consider default values for all pages which i gave in index.html.
Please help me how to make in dynamic.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions