3

Is there a way to implement Google analytics to a specific page.

So, my requirement is to let the user add his/her Google analytics to their page on my application. The page is in sub-route of the application (user/username)

Can I allow a user to do that? Are there any articles related to this?

Comments
  • 4
    Just embed it into the page. If it requires the user to allow for the use of it, then you’ll need to do a check prior to embedding the GA script into the page aswell.

    Hopefully /page/user is a dynamic route so you would only have to add the check once in your code base but do the user check per relevant user.
  • 4
    Oh wait, I so read that wrong

    If you are using a cms of some kind then yes you should be able to allow the user to add their GA ID only as part of their pages fields (prevent xss) and you inject the GA script into their page using their ID on /username lookup.
  • 1
    @C0D4 thanks, I want the user to view the analytics for that page in my application from their GA dashboard, would that be possible. I haven't used GA this my first time and I'm trying to understand as I go!
  • 2
    @C0D4 this what I was talking about!
  • 2
    @cha-m-ra
    So I don’t know about what you’re trying to implement this into.

    But at a high level.
    - Add a field to dbs for GA Id
    - check if user (relevant to page) has stored a value
    - I don’t think you can actually validate a GA Id (I could be wrong)
    - on the /username/user page embed the Ga script with the users GA Id
    - create a plugin for.. lavarel (based on your profile)
    - profit $$$
  • 1
    @C0D4 does GA script only need the ID? won't it ask for the API keys and secret key?
  • 2
    @cha-m-ra if it’s only analytics then no, only the ID, but if I remember correctly, you’ll need to use the cross domain tracker.

    Most other Google services require the secret keys though.
  • 0
    @C0D4 thanks for the help really appreciate it! I'll look into it more!
  • 1
    You could use the GA api, change the id for whatever page you need
  • 0
Add Comment